Opened 10 years ago
Closed 10 years ago
#12303 closed bug (fixed)
Attribute selector fails if the attribute value contains :first :last
Reported by: | Owned by: | timmywil | |
---|---|---|---|
Priority: | blocker | Milestone: | 1.8.2 |
Component: | selector | Version: | 1.8.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Sizzle fails when parsing the following selector:
:input[myattr="value:FirstName"]
It seems like it treats :FirstName as :first pseudo selector. Same can be observed if the value is value:LastName or anything that looks like pseudo selector.
Removing the colon from :input will not trigger the error.
Here are some fiddles demonstrating the scenario:
- working(expected behavior) with version 1.7.1 - http://jsfiddle.net/z9SNK/
- not working with 1.8.0 - http://jsfiddle.net/fN7tp/
- some workaround with 1.8.0 - http://jsfiddle.net/mhwTY/
Change History (15)
comment:1 Changed 10 years ago by
Component: | unfiled → selector |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
comment:2 Changed 10 years ago by
You can't combine a pseudo selector with an attribute selector.
This isn't serious, is it? Where does the documentation states that both cannot be used?
Also it is deprecated and slow.
What is deprecated? Is it documented?
The value for attribute must not be treated as selector, but rather as plain text. Also please note that the behavior is triggered only if there is pseudo selector before the attribute selector. This isn't be normal.
Another example that prove it wrong:
- go to the selectors article: http://api.jquery.com/category/selectors/
quoted from the second paragraph
If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>[email protected][\]`{|}~ ) as a literal part of a name, you must escape the character with two backslashes:
.
- see this fiddle(it selects element) - http://jsfiddle.net/8Dra6/
- this also does select the element - http://jsfiddle.net/Gw3sS/
- this one fails - http://jsfiddle.net/6srwv/
comment:3 Changed 10 years ago by
Milestone: | None → 1.8.1 |
---|---|
Priority: | low → high |
Resolution: | invalid |
Status: | closed → reopened |
No, this is valid. We're erroneously catching :first
et. al. inside attribute selectors when we sweep for positional ones.
comment:4 Changed 10 years ago by
Priority: | high → blocker |
---|---|
Status: | reopened → open |
comment:6 Changed 10 years ago by
Owner: | set to timmywil |
---|---|
Status: | open → assigned |
comment:7 Changed 10 years ago by
Owner: | changed from timmywil to gibson042 |
---|
comment:8 Changed 10 years ago by
I went ahead and did an implementation for this.
@gibson042: I've created a Sizzle issue for the remaining POS problems here: https://github.com/jquery/sizzle/issues/148
comment:9 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Sizzle: POS selectors make more extensive use of tokenization. Fixes #12303.
Changeset: 3a633b0082dbba0365c014ece03d39e8358da18b
comment:10 Changed 10 years ago by
The fix actually doesn't work in jQuery 1.8.1.
"Uncaught RangeError: Maximum call stack size exceeded" exceptions is thrown. Tested in Chrome(21.0.1180.89 m), FF(15.0.1) and IE9. FF even crash when attempt to execute the query.
Here is an example with v. 1.8.1 http://jsbin.com/ecowez/2/edit
comment:11 Changed 10 years ago by
Milestone: | 1.8.1 → 1.8.2 |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
Woopsie. Looks like tokenization was fixed and handlePOS doesn't recognize any part of the selector as POS, but it goes into an infinite loop because the codepath keeps going into handlePOS.
comment:12 Changed 10 years ago by
Owner: | changed from gibson042 to timmywil |
---|---|
Status: | reopened → assigned |
Wow. You might think the tests I added would also go into an infinite loop, but they don't because the regex index for the POS regex is never reset and it returns false on the second check, thus handlePOS is not entered again the second time around. I'm flabbergasted.
comment:15 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I'm not sure why that worked in 1.7.1, but it is clearly wrong. You can't combine a pseudo selector with an attribute selector. If you need to select an attribute, then just use an tag and attribute selector like you do in your last jsfiddle.
Also it is deprecated and slow. Use attribute selector instead.