Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#7673 closed bug (fixed)

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:
Blocked by: Blocking:

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 (11)

comment:1 Changed 10 years ago by ajpiano

Owner: set to sever
Status: newpending

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 Changed 10 years ago by Rick Waldron

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 10 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 10 years ago by Rick Waldron

Resolution: invalid
Status: pendingclosed

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

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

comment:5 Changed 10 years ago by jitter

Component: unfiledattributes
Milestone: 1.next1.4.5
Priority: undecidedhigh
Resolution: invalid
Status: closedreopened

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 10 years ago by jitter

Owner: changed from sever to jitter
Priority: highlow
Status: reopenedassigned

comment:7 Changed 10 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 10 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 10 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 10 years ago by john

Resolution: fixed
Status: assignedclosed

Landed both the Sizzle and jQuery pulls.

comment:11 Changed 10 years ago by jitter

Milestone: 1.4.51.5

Move fixed tickets to appropriate milestone

Note: See TracTickets for help on using tickets.