Skip to main content

Bug Tracker

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="foobar">test</div>
<script>
    $('div').hasClass('foo'); //should return true
</script>

http://jsfiddle.net/2e2Xy/

Attachments (0)
Change History (9)

Changed April 29, 2013 06:14PM UTC by rwaldron comment:1

owner: → rwaldron
status: newassigned

Confirmed.

Additional materials: http://jsfiddle.net/rwaldron/2e2Xy/2/

Changed May 02, 2013 08:34PM UTC by timmywil comment:2

component: unfiledattributes
milestone: None2.0.1
priority: undecidedhigh

Changed May 08, 2013 09:07AM UTC by amine comment:3

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

Changed May 08, 2013 01:19PM UTC by zzzzbov@gmail.com comment:4

Replying to [comment:3 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.

Changed May 08, 2013 01:31PM UTC by dmethvin 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 zzzzbov@gmail.com 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 dmethvin 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 gibson042 comment:8

milestone: 2.0.11.10
owner: rwaldrongibson042

Changed May 14, 2013 01:56AM UTC by Richard Gibson comment:9

resolution: → fixed
status: assignedclosed

Fix #13835: classes separated by form feed

Changeset: d8a35011ec05ed3493a85c1bd699902893cd437c