Bug Tracker

Modify

Ticket #7533 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

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:1 Changed 3 years ago by boushley

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

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.

Last edited 3 years ago by jitter (previous) (diff)

comment:3 Changed 3 years ago by jitter

  • Owner set to jitter
  • Status changed from open to assigned

comment:4 Changed 3 years ago by addyosmani

#7619 is a duplicate of this ticket.

comment:5 Changed 3 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!

 reduced test case

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 3 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 3 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:8 Changed 3 years ago by jitter

  • Blocking 7620 removed

comment:9 Changed 3 years ago by jitter

#7620 is a duplicate of this ticket.

comment:10 Changed 3 years ago by jitter

#7634 is a duplicate of this ticket.

comment:11 Changed 3 years ago by jitter

#7643 is a duplicate of this ticket.

comment:12 Changed 3 years ago by jitter

#7661 is a duplicate of this ticket.

comment:13 Changed 3 years ago by jitter

#7680 is a duplicate of this ticket.

comment:14 Changed 3 years ago by jitter

new  pull request with the solution suggested by John Resig

Last edited 3 years ago by jitter (previous) (diff)

comment:15 Changed 3 years ago by john

  • Status changed from assigned to closed
  • Resolution set to fixed

Landed.

comment:16 Changed 3 years ago by jitter

#7740 is a duplicate of this ticket.

comment:17 Changed 3 years ago by jitter

#7776 is a duplicate of this ticket.

comment:18 Changed 3 years ago by jitter

#7807 is a duplicate of this ticket.

comment:19 Changed 3 years ago by ajpiano

#7820 is a duplicate of this ticket.

comment:20 follow-up: ↓ 21 Changed 3 years ago by ajpiano

#7829 is a duplicate of this ticket.

comment:21 in reply to: ↑ 20 Changed 3 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 3 years ago by ajpiano

#7873 is a duplicate of this ticket.

comment:23 Changed 3 years ago by jitter

  • Milestone changed from 1.4.5 to 1.5

Move fixed tickets to appropriate milestone

comment:24 Changed 3 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.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.