Bug Tracker

Opened 11 years ago

Closed 9 years ago

Last modified 9 years ago

#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@…
Blocked by: Blocking:

Description

Given some elements with apostrophe's in their attribute values:

$("body").append("<span title='James&#39;s'>Here</span>"); $("body").append("<span title='St. James&#39;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&#39;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&#39;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&#39;s&#39; 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 (3)

comment:1 Changed 11 years ago by dmethvin

Component: unfilledselector
Keywords: quotes added
Owner: set to john

comment:2 Changed 9 years ago by Rick Waldron

Resolution: invalid
Status: newclosed

The best part is that the value of the second span'a title attr is "St. James&#39;s Places"... but you actually test for "St. James&#39;s Place" - you're missing an "s".

Please be more careful in the future

http://jsfiddle.net/rwaldron/uZhFj/1/

comment:3 Changed 9 years ago by Rick Waldron

ALSO... There is a typo here as well:

$("[title=\"St. James's Place\"]).text()

Note: See TracTickets for help on using tickets.