Side navigation
#13835 closed bug (fixed)
Opened April 29, 2013 05:30PM UTC
Closed May 14, 2013 01:56AM UTC
hasClass fails when class contains form feed
Reported by: | zzzzbov@gmail.com | 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="foobar">test</div> <script> $('div').hasClass('foo'); //should return true </script>
Attachments (0)
Change History (9)
Changed April 29, 2013 06:14PM UTC by comment:1
owner: | → rwaldron |
---|---|
status: | new → assigned |
Changed May 02, 2013 08:34PM UTC by comment:2
component: | unfiled → attributes |
---|---|
milestone: | None → 2.0.1 |
priority: | undecided → high |
Changed May 08, 2013 09:07AM UTC by comment:3
Hello,
This is not a bug because when you using class"foobar" is similar to
class"foobar" ok but you searching "foo" and not a "foobar"
so it's normal to get the result false
Changed May 08, 2013 01:19PM UTC by comment:4
Replying to [comment:3 amine]:
Hello, This is not a bug because when you using class"foobar" 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="foobar"
, 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
.
Changed May 08, 2013 01:31PM UTC by comment:5
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.
Changed May 08, 2013 01:34PM UTC by comment:6
Replying to [comment:5 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
.
Changed May 08, 2013 01:37PM UTC by comment:7
Oh, true, I was thinking it added a new regex to the loop but it doesn't.
Changed May 13, 2013 04:34PM UTC by comment:8
milestone: | 2.0.1 → 1.10 |
---|---|
owner: | rwaldron → gibson042 |
Confirmed.
Additional materials: http://jsfiddle.net/rwaldron/2e2Xy/2/