Closed Bug 361933 Opened 18 years ago Closed 18 years ago

[FIX]XML serializer should match "encoding" to actual encoding

Categories

(Core :: DOM: Serializers, defect, P1)

x86
Linux
defect

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

Details

Attachments

(2 files, 2 obsolete files)

Right now if I take an XML document that started out as ISO-8859-1 and serialize it as UTF8, we'll happily serialize encoding="ISO-8859-1" in the XML decl. This seems pretty suboptimal, and in particular causes issues with XMLHttpRequest. See the thread at http://lists.w3.org/Archives/Public/public-webapi/2006Nov/0040.html I'll aim to fix the underlying bug here and the XMLHttpRequest issue in a separate bug.
Priority: -- → P1
Summary: XML serializer should match "encoding" to actual encoding → [FIX]XML serializer should match "encoding" to actual encoding
Target Milestone: --- → mozilla1.9alpha
Attached patch Fix (obsolete) — Splinter Review
Attachment #246649 - Flags: superreview?(bugmail)
Attachment #246649 - Flags: review?(bugmail)
Bug 361934 covers the XMLHttpRequest end of things.
Blocks: 361934
Comment on attachment 246649 [details] [diff] [review] Fix + * to a byte stream. If this string is empty and root is + * a document, the document's character set will be used. what happens if I pass an empty string and a non-document root?
We throw. I can document that if desired.
Comment on attachment 246649 [details] [diff] [review] Fix >@@ -997,17 +998,23 @@ nsXMLContentSerializer::AppendDocumentSt > > if (version.IsEmpty()) > return NS_OK; // A declaration must have version, or there is no decl > > NS_NAMED_LITERAL_STRING(endQuote, "\""); > > aStr += NS_LITERAL_STRING("<?xml version=\"") + version + endQuote; > >- if (!encoding.IsEmpty()) { >+ if (!mCharset.IsEmpty()) { >+ aStr += NS_LITERAL_STRING(" encoding=\"") + >+ NS_ConvertASCIItoUTF16(mCharset) + endQuote; >+ } >+ // Otherwise fall back on the document's encoding, I guess... >+ // Though we don't really expect this to happen. >+ else if (!encoding.IsEmpty()) { > aStr += NS_LITERAL_STRING(" encoding=\"") + encoding + endQuote; > } Is this fallback ever really right (other than by just pure chance). Would it be better to not put an encoding attribute there at all rather one that's likely wrong? r/sr=me either way
Attachment #246649 - Flags: superreview?(bugmail)
Attachment #246649 - Flags: superreview+
Attachment #246649 - Flags: review?(bugmail)
Attachment #246649 - Flags: review+
> Is this fallback ever really right (other than by just pure chance) Not really. In fact, we shouldn't even end up in this code if that member is empty... I can just not put the attr there, sure.
Attachment #246649 - Attachment is obsolete: true
Fixed. I'll try to come up with a unit test for this.
Status: NEW → RESOLVED
Closed: 18 years ago
Flags: in-testsuite?
Resolution: --- → FIXED
Attached patch Kinda silly unit test (obsolete) — Splinter Review
This isn't checking that we actually used the specified encoding... I can't quite work out enough about getting non-ASCII data from JS into Gecko in a specified non-UTF8 encoding to do that right this second.
Attached patch Slightly cleanerSplinter Review
Attachment #247043 - Attachment is obsolete: true
Checked in that test
Flags: in-testsuite? → in-testsuite+
Blocks: 367827
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: