Bug Tracker

Opened 11 years ago

Closed 11 years ago

#4091 closed bug (fixed)

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)

test.html (600 bytes) - added by soothsayer 11 years ago.
Sample Code

Download all attachments as: .zip

Change History (7)

Changed 11 years ago by soothsayer

Attachment: test.html added

Sample Code

comment:1 Changed 11 years ago by soothsayer

Forgot to mention,

If I use $('input[name="txtRating["]') as my selector, it works fine on Firefox.

comment:2 Changed 11 years ago by Rwhitbeck

Isn't this $('input[name="txtRating["]') the proper syntax anyways?

Is this even a bug?

comment:3 Changed 11 years ago by soothsayer

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

comment:4 Changed 11 years ago by Rwhitbeck

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.

comment:5 Changed 11 years ago by soothsayer

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!

comment:6 Changed 11 years ago by dmethvin

Resolution: fixed
Status: newclosed

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.

Note: See TracTickets for help on using tickets.