Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#7119 closed bug (worksforme)

Escaping of apostroph(') in selector doesn't work properly

Reported by: pxx Owned by:
Priority: low Milestone: 1.4.3
Component: selector Version: 1.4.2
Keywords: escaping, apostroph, context Cc:
Blocked by: Blocking:

Description

According to documentation, all special symbols in selector should be escaped with 2 backslashes:
.

See the following example: <select><option value="apo'stroph">apo'stroph</option></select>

Query $("option[value=apo
'stroph]") works fine and returns expected option But when I need to define context in query like $("option[value=apo
'stroph]", 'select') or $('select').find("option[value=apo
'stroph]") it crashes with following exception: Syntax error, unrecognized expression: value=apo'stroph]

Change History (2)

comment:1 Changed 13 years ago by addyosmani

Resolution: worksforme
Status: newclosed

In order to make the given selector work, you need to double-escape the value of the option you're trying to select (in this case a little differently to what you originally did).

Whilst you are doing this inside of [value=X], in order for this to correctly work without breaking you need to be double-escaping your selector in a way that maintains clean-syntax as follows:

var val = "apo
'stroph"; var test = $('option[value="'+val+'"]'); console.log(test.length); works console.log(test.val()); works

A live test case of this working can be found here: http://jsfiddle.net/VYtv4/4/

comment:2 Changed 13 years ago by pxx

I am sorry, I didn't know about jsFiddle and issue parser had cut out slashes. Here is my live test case: http://jsfiddle.net/VYtv4/5/ now, just FYI, because it works in newest jQuery version (1.4.3)

Note: See TracTickets for help on using tickets.