Side navigation
#4091 closed bug (fixed)
Opened February 07, 2009 01:53PM UTC
Closed February 12, 2009 04:25AM UTC
Error in escaping selector
Reported by: | soothsayer | Owned by: | |
---|---|---|---|
Priority: | critical | Milestone: | 1.3.2 |
Component: | unfiled | Version: | 1.3.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
If you name a textbox with name="txtRating["
and then use a selector like $("input[name=txtRating\\\\[]")
it gives an error in Firefox only. Works fine on Chrome.
Firebug console reads:
[Exception... "'Syntax error, unrecognized expression: ]' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]
I'm attaching along a sample code to reproduce the bug.
Attachments (1)
Change History (6)
Changed February 07, 2009 01:57PM UTC by comment:1
Changed February 11, 2009 06:35AM UTC by comment:2
Isn't this $('input[name="txtRating["]') the proper syntax anyways?
Is this even a bug?
Changed February 11, 2009 03:02PM UTC by comment:3
Rwhitbeck: The syntax you are using is an alternative I suppose.
As quoted on http://docs.jquery.com/Selectors
Note: if you wish to use any of the meta-characters described above as a literal part of a name, you must escape the character with two backslashes (\\). For example:
#foo\\\\:bar
#foo\\\\[bar\\\\]
#foo\\\\.bar
More important, the point being that it should either work in all browsers or none. That's the essence of jquery as a robust & platform independent framework.
Let me know what you think
Changed February 11, 2009 04:42PM UTC by comment:4
Take a look at this page which more accurately describes what you are trying to do:
http://docs.jquery.com/Selectors/attributeEquals#attributevalue
Specifically the note for arguments value: "An attribute value. Quotes are optional in most cases, but should be used to avoid conflicts when the value contains characters like "]"."
I feel that the example you are giving isn't supported but is working anyways in some browsers.
Changed February 11, 2009 05:08PM UTC by comment:5
Fair enough.
I think this must be brought to more highlight. Added it at the bottom of the http://docs.jquery.com/API/1.3/Selectors page now. Not many people know about this since I discussed this before on IRC, etc and no one could figure out.
Anyway, I really hope this behavior is standardized across browsers. Such a bug in codes would really take long to locate.
Cheers!
Changed February 12, 2009 04:25AM UTC by comment:6
resolution: | → fixed |
---|---|
status: | new → closed |
Since the documentation has been clarified that you should quote special characters, it doesn't seem like there is a lot we can do. Your edit on the Selectors page helps. Different browsers may not handle error cases the same way, but if the values are quoted everything works consistently.
Forgot to mention,
If I use $('input[name="txtRating["]') as my selector, it works fine on Firefox.