Side navigation
#3680 closed bug (fixed)
Opened December 03, 2008 04:44AM UTC
Closed March 08, 2010 09:49PM UTC
Leading/trailing space not treated consistently in className
Reported by: | rmurphey | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.4 |
Component: | core | Version: | 1.3.2 |
Keywords: | Cc: | rebecca@rebeccamurphey.com | |
Blocked by: | Blocking: |
Description
[this probably needs a better description]
I've set up a demo page that shows this bug in detail at:
http://www.rebeccamurphey.com/stuff/classbug/
I am populating a page with HTML contained in a JSON object sent by the server. Once the page is populated, I attempt to run the following jQuery:
$('li.toggle').size()
There are 54 li's that should match; Firefox 3 finds them, but other major browsers do not. I suspect the issue occurs when a class attribute contains some escape characters in the JSON, e.g.:
<li class=\\"toggle\\r\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\">
The following will result in alerts as appropriate, at least in Safari:
$('li).each(function() {
if (this.className.match('toggle')) { alert('match'); }
});
But this will not:
$('li').each(function() {
if (this.className == 'toggle') { alert('match'); }
});
Attachments (2)
Change History (7)
Changed December 03, 2008 01:41PM UTC by comment:1
component: | selector → core |
---|---|
need: | Review → Test Case |
Changed December 03, 2008 03:57PM UTC by comment:2
I've updated the test case at
http://www.rebeccamurphey.com/stuff/classbug/
it wasn't using AJAX before, it was just populating the div with the json when the a#load was clicked.
Changed December 03, 2008 04:32PM UTC by comment:3
Per the test case page I posted, this is a problem in:
- Safari 3.2
- IE6
- IE7
Changed May 06, 2009 03:33AM UTC by comment:4
With a newline in the string, you are creating HTML like:
<li class=\\"toggle ">
}}}
http://www.w3.org/TR/html401/types.html#type-cdata
"User agents may ignore leading and trailing white space in CDATA attribute values (e.g., " myval " may be interpreted as "myval"). Authors should not declare attribute values with leading or trailing white space."
I've attached a test case that shows that even with bare HTML/DOM, Firefox trims the trailing newlines/spaces but IE does not. Both are valid. The test correctly shows that 2 elements are selected in both IE and Firefox.
Whatever the problem is here, it seems that it's very dubious to depend on the behavior of trailing whitespace in a class name.
Changed November 14, 2009 03:33PM UTC by comment:5
summary: | Elements that match selector are found in some browsers, not found in others → Leading/trailing space not treated consistently in className |
---|
Changed November 16, 2009 09:18AM UTC by comment:6
I try to reproduce this bug but without success. Seems fixed to me.
Changed March 08, 2010 09:49PM UTC by comment:7
milestone: | 1.3 → 1.4 |
---|---|
resolution: | → fixed |
status: | new → closed |
version: | 1.2.6 → 1.3.2 |
This has since been fixed in jQuery 1.4.
That's odd, IE's regex engine does match \\r, \\n and \\t when using /\\s/.
Can you provide a test case ? an html file that reproduces the problem.
Try not to use ajax, add the json within a js file and include it.