Commit 9d07525a authored by jaubourg's avatar jaubourg

Makes sure "adding" a string to a Callbacks object doesn't cause a stack...

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.
parent b292c4c2
......@@ -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 );
}
......
......@@ -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" );
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment