Ticket #4394 (closed bug: invalid)
Jquery 1.3.2 (Sizzle) cannot use attribute selectors with an odd number of apostrophes in the values.
| Reported by: | benjamin.keil@… | Owned by: | john |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | selector | Version: | 1.3.2 |
| Keywords: | quotes | Cc: | benjamin.keil@… |
| Blocking: | Blocked by: |
Description
Given some elements with apostrophe's in their attribute values:
$("body").append("<span title='James's'>Here</span>"); $("body").append("<span title='St. James's Places'>There</span>");
I expect $("[title=\"James's\"]").text() to be "Here" and $("[title=\"St. James's Place\"]).text() to be "There".
In the first case what I get (with various attempts at escaping the apostrophe) is:
| $("[title=\"James's\"]").text() | Syntax error, unrecognized expression: title="James's"] |
| $("[title=\"James's\"]").text(); | "" |
| $("[title=James's]").text(); | Syntax error, unrecognized expression: title=James's] |
| $("[title=James\'s]").text(); | Syntax error, unrecognized expression: title=James's] |
| $("[title=James 's]").text(); | Syntax error, unrecognized expression: title=James\'s] |
Trying for the second one, I get slightly different exceptions:
| $("[title=\"St. James's Place\"]").text(); | Syntax error, unrecognized expression: Place"] |
| $("[title=\"St. James's Place\"]").text(); | "" |
| $("[title=St. James's Place]").text(); | Syntax error, unrecognized expression: Place] |
| $("[title=St. James\'s Place]").text(); | Syntax error, unrecognized expression: Place] |
| $("[title=St. James 's Place]").text(); | Syntax error, unrecognized expression: Place] |
If, however, I use an even number of apostrophes, then all is well:
$("body").append("<span title='St. James's' Place'>Yonder</span>");
| $("[title=St. James's' Place]").text(); | "Yonder" |
| $("[title=\"St. James's' Place\"]").text(); | "Yonder" |
| $("[title=St. James\'s\' Place]").text(); | "Yonder" |
| $("[title='St. James\'s\' Place']").text(); | "Yonder" |
Even $("[title='St. James's' Place']").text() results in "Yonder", which I find surprising.
Change History
comment:1 Changed 4 years ago by dmethvin
- Keywords quotes added
- Owner set to john
- Component changed from unfilled to selector
comment:2 Changed 3 years ago by rwaldron
- Status changed from new to closed
- Resolution set to invalid
The best part is that the value of the second span'a title attr is "St. James's Places"... but you actually test for "St. James's Place" - you're missing an "s".
Please be more careful in the future
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
