Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14579 closed bug (fixed)

Inconsistent parsing of unquoted trailing spaces in attribute selector.

Reported by: sakimorix@… Owned by: gibson042
Priority: low Milestone: None
Component: selector Version: 1.11.0-beta2
Keywords: Cc:
Blocked by: Blocking:

Description

Attribute selector handling appears to be inconsistent between the collection factory and other operations like .is(~) and .find(~). Specifically, unquoted trailing spaces in an attribute value are handled differently in some instances.

As a quick example, <div id="xyz" foo="bar">-</div> will be matched by $("div[foo=bar ]") but $("#xyz").is("div[foo=bar ]") yields false. Similarly, $("#xyz").filter("div[foo=bar ]") yields an empty collection.

For a jsFiddle of the above, see: http://jsfiddle.net/9yDjA/

As one would expect, quoting the attribute value always results in the correct behaviour, regardless of how much leading or trailing space is around the value. And while it could be argued that unquoted trailing spaces are bad practice, IMO the real problem here is one of consistency: if a given selector matches an element, it should match in all cases and $(x).is(x) should never return false (provided x does not contain positional components and $(x) is not an empty collection, of course).

Either unquoted spaces (both leading and trailing) should be trimmed in all cases (meaning "div[foo=bar ]" should be interpreted as "div[foo='bar']"), or they should be made part of the value being tested (meaning "div[foo=bar ]" is interpreted as "div[foo='bar ']"). I would prefer the former as that is less likely to break existing code, but would gladly take the latter over the current (inconsistent) behaviour.

I've confirmed this happens on current v1.x releases, both stable (v1.10.2) and beta (v1.11.0b2).

Change History (3)

comment:1 Changed 6 years ago by gibson042

Component: unfiledselector
Owner: set to gibson042
Priority: undecidedlow
Status: newassigned

Confirmed. You must have been doing something very unusual to find this one.

comment:2 Changed 6 years ago by Richard Gibson

Resolution: fixed
Status: assignedclosed

Fix #14579: attribute selectors with trailing spaces after an unquoted value

Changeset: ed20e7c645064822f4070a0c60195e4bcdaba683

comment:3 Changed 6 years ago by anonymous

Very unusual indeed. :)

Many thanks for jumping on this one so quickly!

Note: See TracTickets for help on using tickets.