#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 12 years ago by
Owner: | set to sever |
---|---|
Status: | new → pending |
comment:2 follow-up: 3 Changed 12 years ago by
I'm curious to know what the use case is for having a carriage return in your class attribute.
comment:3 Changed 12 years ago by
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 12 years ago by
Resolution: | → invalid |
---|---|
Status: | pending → closed |
This is not a bug in jQuery. You can EASILY trim that whitespace with jQuery.trim()
comment:5 Changed 12 years ago by
Component: | unfiled → attributes |
---|---|
Milestone: | 1.next → 1.4.5 |
Priority: | undecided → high |
Resolution: | invalid |
Status: | closed → reopened |
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 12 years ago by
Owner: | changed from sever to jitter |
---|---|
Priority: | high → low |
Status: | reopened → assigned |
comment:7 follow-ups: 8 9 Changed 12 years ago by
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 Changed 12 years ago by
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 Changed 12 years ago by
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 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Landed both the Sizzle and jQuery pulls.
comment:11 Changed 12 years ago by
Milestone: | 1.4.5 → 1.5 |
---|
Move fixed tickets to appropriate milestone
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.