Opened 10 years ago
Closed 10 years ago
#13835 closed bug (fixed)
hasClass fails when class contains form feed
Reported by: | Owned by: | gibson042 | |
---|---|---|---|
Priority: | high | Milestone: | 1.10 |
Component: | attributes | Version: | 2.0.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
The HTML5 specification lists classes as being space-separated tokens. http://www.w3.org/html/wg/drafts/html/master/single-page.html#classes
A set of space-separated tokens is a string containing zero or more words (known as tokens) separated by one or more space characters, where words consist of any string of one or more characters, none of which are space characters.
Space characters include:
- space (U+0020)
- tab (U+0009)
- line feed (U+000A)
- form feed (U+000C)
- carriage return (U+000D)
If a DOM node uses a classes separated by a form feed, the class is not found on that element.
<div class="foobar">test</div> <script> $('div').hasClass('foo'); //should return true </script>
Change History (9)
comment:1 Changed 10 years ago by
Owner: | set to Rick Waldron |
---|---|
Status: | new → assigned |
comment:2 Changed 10 years ago by
Component: | unfiled → attributes |
---|---|
Milestone: | None → 2.0.1 |
Priority: | undecided → high |
comment:3 follow-up: 4 Changed 10 years ago by
Hello, This is not a bug because when you using class"foobar" is similar to
class"foo bar" ok but you searching "foo " and not a "foo bar"
so it's normal to get the result false
comment:4 Changed 10 years ago by
Replying to amine:
Hello, This is not a bug because when you using class"foobar" is similar to
class"foobar" ok but you searching "foo" and not a "foobar"
so it's normal to get the result false
in class="foobar"
, the foo
class is separated from the bar
class by a whitespace character: U+000C
which is form feed. The HTML5 specification dictates that classes are space-separated tokens, and form feed is one of the tokens considered to be a space character. Because of this, the element has two classes, foo
, and bar
.
comment:5 follow-up: 6 Changed 10 years ago by
Agreed, I do think formfeed should be treated as whitespace so this is a bug. It's probably going to make .hasClass
a lot slower though.
comment:6 Changed 10 years ago by
Replying to dmethvin:
Agreed, I do think formfeed should be treated as whitespace so this is a bug. It's probably going to make
.hasClass
a lot slower though.
I can't imagine changing rclass = /[\t\r\n]/g
to rclass = /[\t\r\n\f]/g
would have a significant impact on the speed of hasClass
.
comment:7 Changed 10 years ago by
Oh, true, I was thinking it added a new regex to the loop but it doesn't.
comment:8 Changed 10 years ago by
Milestone: | 2.0.1 → 1.10 |
---|---|
Owner: | changed from Rick Waldron to gibson042 |
comment:9 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fix #13835: classes separated by form feed
Changeset: d8a35011ec05ed3493a85c1bd699902893cd437c
Confirmed.
Additional materials: http://jsfiddle.net/rwaldron/2e2Xy/2/