#3743 closed bug (duplicate)
Unable to select elements with ID or class containing backslash (even when escaped)
Reported by: | patridge | Owned by: | john |
---|---|---|---|
Priority: | minor | Milestone: | 1.3 |
Component: | selector | Version: | 1.2.6 |
Keywords: | Cc: | patridge | |
Blocked by: | Blocking: |
Description
When trying to select an id/class that contains a backslash "\", escaping doesn't seem to work. While "\" and the characters that are escapable (".", "$", ",?", "/", etc.) aren't really valid in these attributes according to HTML 4.0, this is the only character that appears to be impossible to find using a selector. Any number of repeated "\" characters appear to resolve to nothing when used as a selector. If this character is intended to be reserved in an id/class, mentioning so in the selector documentation and FAQ would resolve the issue.
Here is the markup in question:
<div id="test\123"></div>
or
<div class="test\123"></div>
Here are some selectors that fail to find either of these divs (but all of them would find <div id="test123"></div> or <div class="test123"></div>, if it were present in the markup):
$("#test123") // => 0 items (0 expected) $("#test\\123") // js-escaped as "#test\123", selector-escaped as "#test123" => 0 items (0 expected) $("#test\\\123") // js-escaped as "#test\123", selector-escaped as "#test123" => 0 items (0 expected) $("#test\\\\123") // ideal documentation case: js-escaped as "#test\\123", should be selector-escaped as "#test\123" => 0 items (1 expected: fail) $(".test\\\\123") // => 0 items (1 expected: fail) [others for class left out intentionally]
Any number of "\" in the selector appear to simply resolve to doing a select without any "\" characters (unless there is a different character to actually escape at the end, such as a "."):
$("#test\\\\\\\\\\\\123") // js-escaped as "#test\\\\\\123", should be selector-escaped as "#test\\\123" => won't find <div id="test\\\123"></div> but will find <div id="test123"></div> just like the other test cases
Change History (7)
comment:1 Changed 14 years ago by
Cc: | patridge added |
---|---|
Owner: | set to john |
comment:2 Changed 14 years ago by
comment:4 Changed 14 years ago by
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 (".").
comment:5 Changed 14 years ago by
The W3 specs (see dmethvin's comment) rule out the need to explicitly support backslashes in IDs but it doesn't help with class attributes, although there is probably another standards doc out there that forbids them for class names (I only did a cursory search on those same w3.org pages).
comment:6 Changed 12 years ago by
Resolution: | → duplicate |
---|---|
Status: | new → closed |
The use of qSA in most cases makes this bug irrelevant except for IE6/7, where it is documented at #6428.
It's working if you use an attribute selector:
[id=test\\123]
so I guess it's because thequickExpr
that should match a single id:^#([\w-]+)$
. Maybe the same stuff should be used instead of[\w-]
, just like in other regular expressions:(?:[\w\u0128-\uFFFF\*_-]|\\.)