From: jaubourg Date: Thu, 16 Aug 2012 17:12:59 +0000 (+0200) Subject: Makes sure "adding" a string to a Callbacks object doesn't cause a stack overflow... X-Git-Tag: 1.8.1~48 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9d07525a71e7bc12f606d8015d21425c5580e262;p=jquery.git Makes sure "adding" a string to a Callbacks object doesn't cause a stack overflow, just ignore the value like 1.7.x righfully did. Fixes #12233. Unit tests added. --- diff --git a/src/callbacks.js b/src/callbacks.js index 893f5760b..37acabcba 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -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 ); } diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index 2bc5c92d6..2c708bb59 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -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" ); +});