Bug Tracker

Modify

Ticket #13835 (closed bug: fixed)

Opened 12 months ago

Last modified 11 months ago

hasClass fails when class contains form feed

Reported by: zzzzbov@… Owned by: gibson042
Priority: high Milestone: 1.10
Component: attributes Version: 2.0.0
Keywords: Cc:
Blocking: Blocked by:

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

comment:1 Changed 12 months ago by rwaldron

  • Owner set to rwaldron
  • Status changed from new to assigned

Confirmed.

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

comment:2 Changed 12 months ago by timmywil

  • Priority changed from undecided to high
  • Component changed from unfiled to attributes
  • Milestone changed from None to 2.0.1

comment:3 follow-up: ↓ 4 Changed 12 months 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 12 months ago by zzzzbov@…

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 follow-up: ↓ 6 Changed 12 months 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 12 months ago by zzzzbov@…

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 12 months ago by dmethvin

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

comment:8 Changed 11 months ago by gibson042

  • Owner changed from rwaldron to gibson042
  • Milestone changed from 2.0.1 to 1.10

comment:9 Changed 11 months ago by Richard Gibson

  • Status changed from assigned to closed
  • Resolution set to fixed

Fix #13835: classes separated by form feed

Changeset: d8a35011ec05ed3493a85c1bd699902893cd437c

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.