mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
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:
parent
b292c4c2df
commit
9d07525a71
@ -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" );
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user