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

jQuery function filter with attribute name contains square bracket is not working #4170

Closed
colandchan opened this issue Sep 3, 2018 · 4 comments

Comments

@colandchan
Copy link

@colandchan colandchan commented Sep 3, 2018

Description

Select elements by name attribute, then use filter with selector. If the selector contains square bracket, sometimes the filter did not work as expected.

In the test case, the first console.log returns 2 as expected.
The second console.log returns 0 which expected to be 1.

Link to test case

http://jsfiddle.net/Lqv9yjn3/1/

@colandchan colandchan changed the title jQuery function filter with attribute name contains bracket is not working jQuery function filter with attribute name contains square bracket is not working Sep 3, 2018
@timmywil
Copy link
Member

@timmywil timmywil commented Sep 3, 2018

This seems valid. However, the easy workaround is to wrap your value in quotes. https://jsfiddle.net/Lqv9yjn3/10/

@dmethvin
Copy link
Member

@dmethvin dmethvin commented Sep 3, 2018

I know we've seen these reports before but I'm too lazy to look it up in closed issues. The CSS spec says:

Attribute values must be identifiers or strings. - https://drafts.csswg.org/css2/selector.html#attribute-selectors

Identifiers don't have ] in them but quoted strings can.

@timmywil
Copy link
Member

@timmywil timmywil commented Sep 3, 2018

Identifiers can have escaped characters. In this case, escaping the ] should work.

@timmywil
Copy link
Member

@timmywil timmywil commented Sep 3, 2018

Actually, this is fixed in Sizzle master (jquery/sizzle#408), but we need to update Sizzle in jQuery.

@timmywil timmywil modified the milestones: 3.4.0, 4.0.0 Apr 2, 2019
@mgol mgol modified the milestones: 4.0.0, 3.4.0 Apr 8, 2019
mgol added a commit to mgol/jquery that referenced this issue Apr 9, 2019
@mgol mgol closed this in #4345 Apr 9, 2019
mgol added a commit that referenced this issue Apr 9, 2019
Fixes gh-1756
Fixes gh-4170
Fixes gh-4249
Closes gh-4345
mgol added a commit that referenced this issue Apr 9, 2019
(cherry-picked from 0b2c36a)

Fixes gh-1756
Fixes gh-4170
Fixes gh-4249
Closes gh-4345
@lock lock bot locked as resolved and limited conversation to collaborators Oct 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants