Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13835 closed bug (fixed)

hasClass fails when class contains form feed

Reported by: [email protected] 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&#12;bar">test</div>
<script>
    $('div').hasClass('foo'); //should return true
</script>

http://jsfiddle.net/2e2Xy/

Change History (9)

comment:1 Changed 10 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: newassigned

Confirmed.

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

comment:2 Changed 10 years ago by timmywil

Component: unfiledattributes
Milestone: None2.0.1
Priority: undecidedhigh

comment:3 Changed 10 years ago by amine

Hello, This is not a bug because when you using class"foo&#12;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 in reply to:  3 Changed 10 years ago by [email protected]

Replying to amine:

Hello, This is not a bug because when you using class"foo&#12;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&#12;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 Changed 10 years ago by 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.

comment:6 in reply to:  5 Changed 10 years ago by [email protected]

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 dmethvin

Oh, true, I was thinking it added a new regex to the loop but it doesn't.

comment:8 Changed 10 years ago by gibson042

Milestone: 2.0.11.10
Owner: changed from Rick Waldron to gibson042

comment:9 Changed 10 years ago by Richard Gibson

Resolution: fixed
Status: assignedclosed

Fix #13835: classes separated by form feed

Changeset: d8a35011ec05ed3493a85c1bd699902893cd437c

Note: See TracTickets for help on using tickets.