Bug Tracker

Modify

Ticket #4091 (closed bug: fixed)

Opened 4 years ago

Last modified 4 years ago

Error in escaping selector

Reported by: soothsayer Owned by:
Priority: critical Milestone: 1.3.2
Component: unfiled Version: 1.3.1
Keywords: Cc:
Blocking: Blocked by:

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

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

Change History

Changed 4 years ago by soothsayer

Sample Code

comment:1 Changed 4 years ago by soothsayer

Forgot to mention,

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

comment:2 Changed 4 years ago by Rwhitbeck

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

Is this even a bug?

comment:3 Changed 4 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 4 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 4 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 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to fixed

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.

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.