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.

This commit is contained in:
jaubourg 2012-08-16 19:12:59 +02:00
parent b292c4c2df
commit 9d07525a71
2 changed files with 12 additions and 2 deletions

View 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 );
}

View 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" );
});