Ticket #7533 (closed bug: fixed)
Problem with id containing a period
| Reported by: | kiequoo | Owned by: | jitter |
|---|---|---|---|
| Priority: | high | Milestone: | 1.5 |
| Component: | selector | Version: | 1.4.4 |
| Keywords: | regression, needsreview | Cc: | |
| Blocking: | Blocked by: |
Description
When creating a jQuery object from a piece of html, if an id attribute within the HTML contains a period, this breaks the find command and it never returns a result. This is best seen in this example in jsFiddle: http://jsfiddle.net/2gHqc/ - when run with jQuery 1.4.4 the alert displays 0, in previous versions of jQuery it returns 1.
Change History
comment:2 Changed 3 years ago by jitter
- Keywords regression, needsreview added
- Priority changed from undecided to high
- Status changed from new to open
- Component changed from unfiled to selector
- Milestone changed from 1.5 to 1.4.5
The issue is a bit more complex, as in HTML 5 basically everything is allowed as ID token.
A possible start/idea for a fix could be what I tried on this pull request.
Not sure if I catched all relevant characters in the regexp, please double check. I will update when necessary.
comment:5 Changed 2 years ago by jitter
- Blocking 7620 added
(In #7620) Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a testcase!
jQuery has sometimes issues when the id attribute contains meta characters. Here it is triggered as jQuery internally uses the present id attribute to speed up the search. Check on #7533 which (once fixed) should also fix this bug.
comment:6 follow-up: ↓ 7 Changed 2 years ago by anonymous
Having a non escaped period (.) maybe valid for the HTML attribute value but *not* the CSS selector. QSA is correct when it chokes on the non-escaped IDs. http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
Because jQuery is dynamically constructing selectors it bares the responsibility of escaping them in those instances.
comment:7 in reply to: ↑ 6 Changed 2 years ago by jitter
Replying to anonymous:
QSA is correct when it chokes on the non-escaped IDs.
And nobody claims otherwise. That's why this ticket got accepted as valid and has a patch pending.
comment:10 Changed 2 years ago by jitter
#7634 is a duplicate of this ticket.
comment:11 Changed 2 years ago by jitter
#7643 is a duplicate of this ticket.
comment:12 Changed 2 years ago by jitter
#7661 is a duplicate of this ticket.
comment:13 Changed 2 years ago by jitter
#7680 is a duplicate of this ticket.
comment:14 Changed 2 years ago by jitter
new pull request with the solution suggested by John Resig
comment:15 Changed 2 years ago by john
- Status changed from assigned to closed
- Resolution set to fixed
Landed.
comment:16 Changed 2 years ago by jitter
#7740 is a duplicate of this ticket.
comment:17 Changed 2 years ago by jitter
#7776 is a duplicate of this ticket.
comment:18 Changed 2 years ago by jitter
#7807 is a duplicate of this ticket.
comment:19 Changed 2 years ago by ajpiano
#7820 is a duplicate of this ticket.
comment:20 follow-up: ↓ 21 Changed 2 years ago by ajpiano
#7829 is a duplicate of this ticket.
comment:21 in reply to: ↑ 20 Changed 2 years ago by anonymous
Replying to ajpiano:
#7829 is a duplicate of this ticket.
#7829 is not a duplicate, please see the demo here: http://jsfiddle.net/QYUPQ/1/
You can compare it to: http://jsfiddle.net/QYUPQ/
comment:22 Changed 2 years ago by ajpiano
#7873 is a duplicate of this ticket.
comment:23 Changed 2 years ago by jitter
- Milestone changed from 1.4.5 to 1.5
Move fixed tickets to appropriate milestone
comment:24 Changed 2 years ago by jitter
#8021 is a duplicate of this ticket.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

And having a period in the id is valid according to the W3 "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")." http://www.w3.org/TR/html401/types.html#type-name