Ticket #6798 (closed bug: invalid)
XML parsing fails with different keywords in different browsers
| Reported by: | llimllib | Owned by: | |
|---|---|---|---|
| Priority: | Milestone: | 1.4.3 | |
| Component: | core | Version: | 1.4.2 |
| Keywords: | xml webkit firefox mac | Cc: | |
| Blocking: | Blocked by: |
Description
Using Chrome 5.0.375.99 beta, Safari Version 5.0 (5533.16), and Firefox 3.5.10, all on Mac OS X 10.5.8, these tests return different values:
test("jQuery XML bug", function() {
expect(3);
equals(jQuery('<?xml version="1.0" ?><x><html></html></x>').children().length, 1, "fails in both webkit and firefox");
equals(jQuery('<?xml version="1.0" ?><x><title></title></x>').children().length, 1, "fails in webkit but not firefox");
equals(jQuery('<?xml version="1.0" ?><x><titles></titles></x>').children().length, 1, "works on both");
});
Different keywords will cause this bug to occur on each of the browsers. Here's the results of a brief test on Firefox:
>>> function test(t) { return jQuery("<x><"+t+">testing</"+t+"></x>").find(t).length; }
>>> jQuery.map(["title", "Title", "span", "div", "html", "body", "h1", "script", "em"], function(x) { return [x, test(x)]; });
["title", 1, "Title", 1, "span", 1, "div", 1, "html", 0, "body", 0, "h1", 1, "script", 0, "em", 1]
and on Chrome:
> function test(t) { return jQuery("<x><"+t+">testing</"+t+"></x>").find(t).length; }
> jQuery.map(["title", "Title", "span", "div", "html", "body", "h1", "script", "em"], function(x) { return [x, test(x)]; });
["title", 0, "Title", 0, "span", 1, "div", 1, "html", 0, "body", 0, "h1", 1, "script", 0, "em", 1]
This bug matters to me, and I discovered it because the XML returned by the Amazon Ecommerce web service appears to parse correctly, but the <title> attribute just seems to have disappeared.
Change History
comment:2 Changed 3 years ago by llimllib
Also, the <title> information appears to be lost at line 489 of src/manipulation.js .
I'm happy to make a fix and submit a patch, but I'd need to be instructed on how you'd like this fixed as it's non-obvious. Should there be another code path for XML than for HTML?
Anyway, if you want to tell me, I'm happy develop a patch, otherwise, I'm afraid I wouldn't be helping much to try and develop one any further.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

By the way, the bit of the docs that made me think that this should work properly is this:
from http://api.jquery.com/jQuery/