Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12394 closed bug (wontfix)

Syntax error, unrecognized expression: with .is() contains matching

Reported by: webmaster@… Owned by:
Priority: low Milestone: None
Component: selector Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:

Description

The following no longer works in the latest JQuery:

$('div').is('div[attribute~=multi text]')

Producing the error: Syntax error, unrecognized expression: div[attribute~=multi text]

It can be fixed by adding speach marks:

$('div').is('div[attribute~="multi text"]')

However, the version without speach marks works with the normal selector:

$('div[attribute~=multi text]')

Which suggests to me this is a bug, and not a new contraint on matching strings that contain spaces.

Change History (4)

comment:1 Changed 7 years ago by webmaster@…

Correction, the version without the speach marks should be acting as logical or and is not the same as "multi text". It does not fix this issue. It's a bug. As per documentation for ~=:

"This selector matches the test string against each word in the attribute value, where a "word" is defined as a string delimited by whitespace. The selector matches if the test string is exactly equal to any of the words."

comment:2 Changed 7 years ago by dmethvin

Component: unfiledselector
Priority: undecidedlow

Please create test cases when possible, it helps us determine whether something is a bug. Here is what I created: http://jsfiddle.net/ns8ft/

Note that the native querySelectorAll throws a syntax error. That tells you the selector is invalid without quotes. When a selector isn't valid we don't guarantee consistent behavior, but I'll leave this open for review to see if we need to take any action.

comment:3 Changed 7 years ago by timmywil

Status: newopen

We insert quotes for attribute values when using .is(),. This was done a while ago to take advantage of matchesSelector whenever possible. We could do the same with the main selection, but in general, the more complex selectors that may contain = or ] characters but aren't attribute selectors are seen being passed to the main selection function. Also, it would add another string replace to everyone's selection.

Nevertheless, these may not be good enough reasons to not do it. Either way, this is low priority.

comment:4 Changed 7 years ago by timmywil

Resolution: wontfix
Status: openclosed

We are now doing slightly stricter selector validation. I'd like to keep it the way it is for now so we can continue to slowly move closer towards the spec.

A couple notes:

  1. it has been this way since the introduction of matchesSelector.
  2. It has never worked in non-matchesSelector browsers so the results have never been reliable without quotes.
Note: See TracTickets for help on using tickets.