Skip to content

Null attributes #1516

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 5 commits into from
Closed

Conversation

scottgonzalez
Copy link
Member

jQuery now returns `null` for empty attributes instead of `undefined`
jQuery now returns `null` for empty attributes instead of `undefined`.
jQuery now returns `null` for empty attributes instead of `undefined`.
jQuery now returns `null` for empty attributes instead of `undefined`.
jQuery now returns `null` for empty attributes instead of `undefined`.
@tjvantoll
Copy link
Member

Looks good. Out of curiosity how did you find the files to change? I'm assuming failing tests?

This seems like something that has the potential to break things unexpectedly.

@scottgonzalez
Copy link
Member Author

Yup, failing tests. No idea what else will break in the wild. The core team decided to just do it and see what happens. See jquery/jquery#2118.

@fnagel
Copy link
Member

fnagel commented Mar 25, 2015

Code looks good, no actual testing.

I agree with TJ that this is a potentially very dangerous change. Most non-frontend dev are used to always use strict comparison.

@scottgonzalez
Copy link
Member Author

What's potentially dangerous? The core change or the UI change?

@scottgonzalez
Copy link
Member Author

@timmywil said to bring this up in the next core meeting. The fact that this change broke UI might cause them to back it out.

@tjvantoll
Copy link
Member

Just to clarify I meant that the Core change is potentially dangerous.

@scottgonzalez
Copy link
Member Author

Ok, that's what I thought. I just wanted to make sure.

@fnagel
Copy link
Member

fnagel commented Mar 25, 2015

What TJ said.

@@ -305,11 +305,11 @@ window.domEqual = function( selector, modifier, message ) {
result = {};
$.each( properties, function( index, attr ) {
var value = elem.prop( attr );
result[ attr ] = value !== undefined ? value : "";
result[ attr ] = value != null ? value : "";
Copy link
Member

Choose a reason for hiding this comment

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

This strict comparison was fine as-is; .prop lacks the DOM semantics that urged us to try changing .attr.

Copy link
Member

Choose a reason for hiding this comment

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

And looking at the broader context, domEqual might still work if you stopped doing this empty-string normalization altogether and just assigned results from .prop and .attr directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

We do the normalization because of space delimited attributes, the most common one being class. The attribute will start out undefined, but after elem.addClass( "foo" ).removeClass( "foo" ), the attribute will be an empty string. We consider this equivalent.

For the property check, the aim was just consistency in the logic. I don't think we've ever consider null and undefined to be non-equivalent in our check.

scottgonzalez added a commit that referenced this pull request Mar 25, 2015
jQuery now returns `null` for empty attributes instead of `undefined`

Ref gh-1516
scottgonzalez added a commit that referenced this pull request Mar 25, 2015
jQuery now returns `null` for empty attributes instead of `undefined`.

Ref gh-1516
scottgonzalez added a commit that referenced this pull request Mar 25, 2015
jQuery now returns `null` for empty attributes instead of `undefined`.

Ref gh-1516
scottgonzalez added a commit that referenced this pull request Mar 25, 2015
jQuery now returns `null` for empty attributes instead of `undefined`.

Ref gh-1516
@scottgonzalez scottgonzalez deleted the null-attributes branch March 26, 2015 18:48
scottgonzalez added a commit that referenced this pull request Jun 9, 2016
jQuery now returns `null` for empty attributes instead of `undefined`

Ref gh-1516

(cherry picked from commit 1264373)
scottgonzalez added a commit that referenced this pull request Jun 9, 2016
jQuery now returns `null` for empty attributes instead of `undefined`.

Ref gh-1516

(cherry picked from commit e4363ab)
scottgonzalez added a commit that referenced this pull request Jun 9, 2016
jQuery now returns `null` for empty attributes instead of `undefined`.

Ref gh-1516

(cherry picked from commit fdbb85b)
scottgonzalez added a commit that referenced this pull request Jun 9, 2016
jQuery now returns `null` for empty attributes instead of `undefined`.

Ref gh-1516

(cherry picked from commit e109e76)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants