Bug Tracker

Modify

Ticket #7673 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

hasClass, removeClass don't work in IE if attribute contains \r character

Reported by: sever Owned by: jitter
Priority: low Milestone: 1.5
Component: attributes Version: 1.4.4
Keywords: Cc:
Blocking: Blocked by:

Description

hasClass, removeClass methods don't work in IE (ver. 7 & 8) if class attribute contains \r character. I have modified regular expression used in hasClass function: /[\n\t]/g => /[\r\n\t]/g After this change hasClass, removeClass, removeAttr methods works fine.

Change History

comment:1 Changed 3 years ago by ajpiano

  • Owner set to sever
  • Status changed from new to pending

Thanks for taking the time to contribute to the jQuery project by filing a ticket. We require that all bugs include a test case on jsFiddle ( http://jsfiddle.net) that clearly demonstrates the issue. If you could please provide such a test case and link it here, we can proceed and investigate this issue.

If you would like to provide a patch, please do so via Github. Thanks again.

comment:2 follow-up: ↓ 3 Changed 3 years ago by rwaldron

I'm curious to know what the use case is for having a carriage return in your class attribute.

comment:3 in reply to: ↑ 2 Changed 3 years ago by anonymous

Replying to rwaldron:

I'm curious to know what the use case is for having a carriage return in your class attribute.

I have html code formed by XSLT. For example:

<td>
<xsl:attribute name="class">

class1 class2 class3

</xsl:attribute>
</td>


in html we will see:
<td class="

class1 class2 class3

">
</td>

comment:4 Changed 3 years ago by rwaldron

  • Status changed from pending to closed
  • Resolution set to invalid

This is not a bug in jQuery. You can EASILY trim that whitespace with jQuery.trim()

 http://jsfiddle.net/rwaldron/PWuW5/

comment:5 Changed 3 years ago by jitter

  • Priority changed from undecided to high
  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Component changed from unfiled to attributes
  • Milestone changed from 1.next to 1.4.5

This may be an edge case and could be avoided in the first case but I think this bug is valid. The specs say browser should ignore carriage return characters in the className property (which they do) but jQuery doesn't and thus creates a inconsistency.

comment:6 Changed 3 years ago by jitter

  • Owner changed from sever to jitter
  • Priority changed from high to low
  • Status changed from reopened to assigned

comment:7 follow-ups: ↓ 8 ↓ 9 Changed 3 years ago by dmethvin

No debate would be complete without a reference to a spec:

This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters. --  http://www.w3.org/TR/html401/struct/global.html#h-7.5.2

White space (spaces, newlines, tabs, and comments) may appear before or after each section. --  http://www.w3.org/TR/html401/struct/global.html#h-7.1

The \r isn't mentioned but since \n and \r often go together it seems reasonable to accept both.

comment:8 in reply to: ↑ 7 Changed 3 years ago by sever

Replying to dmethvin:

The \r isn't mentioned but since \n and \r often go together it seems reasonable to accept both.

In my case '\r' appears right after the last class name: 'class1 class2\r'.

comment:9 in reply to: ↑ 7 Changed 3 years ago by jitter

Replying to dmethvin:

The \r isn't mentioned but since \n and \r often go together it seems reasonable to accept both.

The class attribute if defined as cdata-list and the specs for cdata ( http://www.w3.org/TR/html401/types.html#type-cdata) say

  • Ignore line feeds

comment:10 Changed 3 years ago by john

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

Landed both the Sizzle and jQuery pulls.

comment:11 Changed 3 years ago by jitter

  • Milestone changed from 1.4.5 to 1.5

Move fixed tickets to appropriate milestone

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.