Skip to content
Permalink
Browse files

Makes sure "adding" a string to a Callbacks object doesn't cause a st…

…ack overflow, just ignore the value like 1.7.x righfully did. Fixes #12233. Unit tests added.
  • Loading branch information...
jaubourg committed Aug 16, 2012
1 parent b292c4c commit 9d07525a71e7bc12f606d8015d21425c5580e262
Showing with 12 additions and 2 deletions.
  1. +3 −2 src/callbacks.js
  2. +9 −0 test/unit/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 );
}
@@ -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" );
});

0 comments on commit 9d07525

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.