Skip to content

Bugfix for #15213: calling .empty() on disabled callbacks object kind of re-enables it #1643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

TheDistantSea
Copy link

Copying description from jQuery bug tracker:


Earlier today I answered this StackOverflow question, wherein this behavior is shown:

var c = $.Callbacks();
var f = /* some function */;
c.disable();
c.empty();
c.add(f);
c.disabled(); // of course true
c.fire(); // invokes f!

This behavior occurs in all versions of jQuery I tested (latest 1.9, 1.10, 1.11, 2.0, 2.1) -- here's a fiddle to easily reproduce it.

The problem is that .disable() relies on setting internal variables of the callbacks object to undefined, and while most other methods such as .add() test and this condition and abort if true, .empty() itself does not. Instead it resets some of those variables, which causes the abort test in the other methods to erroneously pass and ultimately for callbacks to be added to and invoked by a disabled object.

…lmost but not quite fully re-enable a disabled callbacks object.
@dmethvin
Copy link
Member

Thanks for the PR! We'll want a few new unit tests to go with this as well. I'd want to test the case where there is an empty list, and one where there is already something in the list. Also be sure you've signed our CLA.

@scottgonzalez
Copy link
Member

@TheDistantSea Using an email address that won't deliver email isn't a valid way to sign the CLA. You also didn't provide your full name.

@dmethvin
Copy link
Member

dmethvin commented Dec 1, 2014

@TheDistantSea It doesn't look like you've signed the CLA yet. Would you like credit for the fix?

@dmethvin dmethvin self-assigned this Dec 3, 2014
@jaubourg
Copy link
Member

jaubourg commented Dec 4, 2014

lgtm!

@dmethvin dmethvin closed this in bc1cb12 Dec 8, 2014
dmethvin added a commit that referenced this pull request Dec 8, 2014
Thanks to @TheDistantSea for the report!

Fixes gh-1790
Closes gh-1643
(cherry picked from commit bc1cb12)
@TheDistantSea
Copy link
Author

@dmethvin I wasn't around and missed the action (in fact had forgotten about all this) but no complaints. Glad to have helped a little bit.

dmethvin added a commit that referenced this pull request Nov 10, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants