Bug Tracker

Modify

Ticket #4394 (closed bug: invalid)

Opened 4 years ago

Last modified 3 years ago

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&#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

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&#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 3 years ago by rwaldron

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

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

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.