Skip to content
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

Attributes: Avoid infinite recursion on non-lowercase attribute getters #3134

Merged
merged 3 commits into from
Jun 3, 2016

Conversation

mgol
Copy link
Member

@mgol mgol commented May 29, 2016

Summary

Attribute hooks are determined for the lowercase versions of attribute names
but this has not been reflected in the bool attribute hooks. The code that
temporarily removed a handler to avoid an infinite loop was removing an
incorrect handler causing stack overflow.

Fixes gh-3133
Refs gh-2914
Refs gh-2916

+2 bytes

Checklist

Mark an [x] for completed items, if you're not sure leave them unchecked and we can assist.

Thanks! Bots and humans will be around shortly to check it out.

"SELECTED"
], function() {
try {
jQuery( "<div>" ).attr( this );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a test that mixed-case attributes are correctly retrieved? This just ensures they don't throw but not that they yield correct results.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll change that.

What do you think about the try-catch approach? Or should I just check assertions and rely on QUnit to fail when it throws? I thought the try-catch approach is better here where I'm specifically testing that no error is thrown.

@dmethvin
Copy link
Member

This does seem like it will be more effective at avoiding the infinite loop. 😺

@mgol
Copy link
Member Author

mgol commented May 29, 2016

@dmethvin I was surprised we have no tests for that! (oops)

@mgol
Copy link
Member Author

mgol commented May 29, 2016

PR updated. I added another commit that fixes an older test that was introducing side effects, in turn causing the test I've just added to fail only on even runs. 😄


attrHandle[ name.toLowerCase() ] = function( elem, name, isXML ) {
var ret, handle,
lowercaseName = name.toLowerCase();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's going to be a variable anyway, why not introduce it earlier?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where earlier? That's the beginning of the function, this name is different
than the one before its definition.

Michał Gołębiowski

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if someone repurposes it, but point taken.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's only +2 bytes so I didn't want to break that unofficial contract.

@mgol
Copy link
Member Author

mgol commented Jun 3, 2016

Any further remarks? Is this good to land?

mgol added 2 commits June 3, 2016 11:51
One test in the attribute module was overwriting jQuery.expr.attrHandle.checked
and wasn't restoring the original state after it finished. It started causing
issues for another checked-related test.
Attributes are no longer always treated as lowercase, although hooks for
them are. This commit fixes a no longer correct comment.
@dmethvin
Copy link
Member

dmethvin commented Jun 3, 2016

LGTM

1 similar comment
@gibson042
Copy link
Member

LGTM

Attribute hooks are determined for the lowercase versions of attribute names
but this has not been reflected in the bool attribute hooks. The code that
temporarily removed a handler to avoid an infinite loop was removing an
incorrect handler causing stack overflow.

Fixes jquerygh-3133
Refs jquerygh-2914
Refs jquerygh-2916
Closes jquerygh-3134
@mgol mgol merged commit e06fda6 into jquery:master Jun 3, 2016
@mgol mgol deleted the boolean-getters branch June 3, 2016 20:55
@mgol mgol removed the Needs review label Sep 25, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Katochimoto pushed a commit to EverexIO/jquery that referenced this pull request Apr 17, 2019
Attribute hooks are determined for the lowercase versions of attribute names
but this has not been reflected in the bool attribute hooks. The code that
temporarily removed a handler to avoid an infinite loop was removing an
incorrect handler causing stack overflow.

Fixes jquerygh-3133
Refs jquerygh-2914
Refs jquerygh-2916
Closes jquerygh-3134
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.

Boolean attribute getters throw if the attribute name is not all lowercase
6 participants