Open
Bug 1142480
Opened 10 years ago
Updated 3 years ago
XMLSerializer adds newline after doctype
Categories
(Core :: DOM: Core & HTML, defect, P5)
Tracking
()
NEW
People
(Reporter: roan.kattouw, Unassigned)
Details
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:36.0) Gecko/20100101 Firefox/36.0
Build ID: 20150306140254
Steps to reproduce:
html = '<!DOCTYPE html><html><body>Hello</body></html>';
xmlDom = new DOMParser().parseFromString(html,'text/xml');
new XMLSerializer().serializeToString(xmlDom);
Actual results:
"<!DOCTYPE html>
<html><body>Hello</body></html>"
Expected results:
"<!DOCTYPE html><html><body>Hello</body></html>"
Updated•10 years ago
|
Component: Untriaged → DOM
Product: Firefox → Core
Comment 1•10 years ago
|
||
nsDOMSerializer (http://mxr.mozilla.org/mozilla-central/source/dom/base/nsDOMSerializer.cpp) calls through to nsDocumentEncoder (http://mxr.mozilla.org/mozilla-central/source/dom/base/nsDocumentEncoder.cpp) which calls through to nsXMLContentSerializer (http://mxr.mozilla.org/mozilla-central/source/dom/base/nsXMLContentSerializer.cpp) which explicitly wants to add a newline after the root node for some reason. See checks for MaybeFlagNewlineForRootNode and calls to MaybeAddNewlineForRootNode.
Comment 2•10 years ago
|
||
Peanut gallery observation: There's little harm from this. DOM Level 3 Core states that a Document can only have for its child nodes one element, processing instructions, comments, and one DocumentType. [1] WHATWG's DOM spec goes further, specifying the order. [2]
So in reparsing the document, the extra new line is removed.
Now, as a purist and someone interested in authoring & editing, I see your point. What I'm saying is that the DOM doesn't preserve that information at the parsing step, so serializers may be free to do what they want.
[1] http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-1590626202
[2] https://dom.spec.whatwg.org/#node-tree
I did some checking and this is the behaviour going back to at least Firefox 13.0a1 (as far back as I could go with mozregression). Marking this as confirmed but someone should decide if this is something we need to fix or accept as the "normal" behaviour.
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Linux → All
Hardware: x86_64 → All
Comment 4•7 years ago
|
||
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046
Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.
If you have questions, please contact :mdaly.
Priority: -- → P5
Assignee | ||
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
Updated•3 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•