Side navigation
#7119 closed bug (worksforme)
Opened October 06, 2010 01:00PM UTC
Closed October 06, 2010 03:31PM UTC
Last modified October 18, 2010 10:16AM UTC
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]
Attachments (0)
Change History (2)
Changed October 06, 2010 03:31PM UTC by comment:1
resolution: | → worksforme |
---|---|
status: | new → closed |
Changed October 18, 2010 10:16AM UTC by comment:2
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)
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/