]> source.dussan.org Git - jquery.git/commitdiff
Makes sure "adding" a string to a Callbacks object doesn't cause a stack overflow...
authorjaubourg <j@ubourg.net>
Thu, 16 Aug 2012 17:12:59 +0000 (19:12 +0200)
committerjaubourg <j@ubourg.net>
Thu, 16 Aug 2012 17:12:59 +0000 (19:12 +0200)
src/callbacks.js
test/unit/callbacks.js

index 893f5760b3bc6911abc1d707879e5af62f7b0d22..37acabcba0ebca5ddd513a08d90a4e6dd388ce70 100644 (file)
@@ -92,9 +92,10 @@ jQuery.Callbacks = function( options ) {
                                        var start = list.length;
                                        (function add( args ) {
                                                jQuery.each( args, function( _, arg ) {
-                                                       if ( jQuery.isFunction( arg ) && ( !options.unique || !self.has( arg ) ) ) {
+                                                       var type = jQuery.type( arg );
+                                                       if ( type === "function" && ( !options.unique || !self.has( arg ) ) ) {
                                                                list.push( arg );
-                                                       } else if ( arg && arg.length ) {
+                                                       } else if ( arg && arg.length && type !== "string" ) {
                                                                // Inspect recursively
                                                                add( arg );
                                                        }
index 2bc5c92d6b8ce91f3a34845f9de24939848d0f5a..2c708bb59a02cfd0f921fd65bd17e181e65be44c 100644 (file)
@@ -250,3 +250,12 @@ test( "jQuery.Callbacks.remove - should remove all instances", function() {
                ok( true, "end of test" );
        }).remove( fn ).fire();
 });
+
+test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function() {
+
+       expect( 1 );
+
+       jQuery.Callbacks().add( "hello world" );
+
+       ok( true, "no stack overflow" );
+});