Diff
Modified: trunk/LayoutTests/ChangeLog (114058 => 114059)
--- trunk/LayoutTests/ChangeLog 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/LayoutTests/ChangeLog 2012-04-13 00:58:30 UTC (rev 114059)
@@ -1,3 +1,22 @@
+2012-04-12 Rob Buis <[email protected]>
+
+ XMLSerializer().serializeToString() doesn't generate the XML declaration markup like Opera and Firefox
+ https://bugs.webkit.org/show_bug.cgi?id=83432
+
+ Reviewed by Ryosuke Niwa.
+
+ Verify that xml declaration gets serialized if present. The updated test results are improvements.
+
+ * fast/dom/dom-parse-serialize-display-expected.txt:
+ * fast/dom/dom-parse-serialize-expected.txt:
+ * fast/dom/dom-parse-serialize-xmldecl-expected.txt: Added.
+ * fast/dom/dom-parse-serialize-xmldecl.html: Added.
+ * fast/xmlhttprequest/xmlhttprequest-get-expected.txt:
+ * fast/xsl/xslt-processor-expected.txt:
+ * http/tests/xmlhttprequest/xml-encoding-expected.txt:
+ * platform/chromium-mac/fast/xmlhttprequest/xmlhttprequest-get-expected.txt:
+ * platform/chromium-win/fast/xmlhttprequest/xmlhttprequest-get-expected.txt:
+
2012-04-12 Tony Payne <[email protected]>
Convert layout test resource PNGs to sRGB. Some tests, such as
Modified: trunk/LayoutTests/fast/dom/dom-parse-serialize-display-expected.txt (114058 => 114059)
--- trunk/LayoutTests/fast/dom/dom-parse-serialize-display-expected.txt 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/LayoutTests/fast/dom/dom-parse-serialize-display-expected.txt 2012-04-13 00:58:30 UTC (rev 114059)
@@ -19,7 +19,7 @@
document object serialized
-<?xml-stylesheet href="" type="text/css"?><!DOCTYPE doc><doc>
+<?xml version="1.0"?><?xml-stylesheet href="" type="text/css"?><!DOCTYPE doc><doc>
<foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>
<d id="id3">Three</d>
</doc>
Modified: trunk/LayoutTests/fast/dom/dom-parse-serialize-expected.txt (114058 => 114059)
--- trunk/LayoutTests/fast/dom/dom-parse-serialize-expected.txt 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/LayoutTests/fast/dom/dom-parse-serialize-expected.txt 2012-04-13 00:58:30 UTC (rev 114059)
@@ -18,7 +18,7 @@
document object serialized
-<!DOCTYPE doc><doc>
+<?xml version="1.0"?><!DOCTYPE doc><doc>
<foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>
<d id="id3">Three</d>
<f id="&<>">Four&<></f><empty/><empty/></doc>
Added: trunk/LayoutTests/fast/dom/dom-parse-serialize-xmldecl-expected.txt (0 => 114059)
--- trunk/LayoutTests/fast/dom/dom-parse-serialize-xmldecl-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/dom-parse-serialize-xmldecl-expected.txt 2012-04-13 00:58:30 UTC (rev 114059)
@@ -0,0 +1,15 @@
+This test verifies that the xml declaration gets serialized if present.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS new XMLSerializer().serializeToString(xmldoc).replace(/"/g,"'") is "<?xml version='1.0' encoding='UTF-8'?><root><test/></root>"
+PASS new XMLSerializer().serializeToString(xmldoc).replace(/"/g,"'") is "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><root><test/></root>"
+PASS new XMLSerializer().serializeToString(xmldoc).replace(/"/g,"'") is "<?xml version='1.0' encoding='UTF-8' standalone='no'?><root><test/></root>"
+PASS new XMLSerializer().serializeToString(xmldoc).replace(/"/g,"'") is "<?xml version='1.0' standalone='yes'?><root><test/></root>"
+PASS new XMLSerializer().serializeToString(xmldoc).replace(/"/g,"'") is "<?xml version='1.0' standalone='no'?><root><test/></root>"
+PASS new XMLSerializer().serializeToString(xmldoc).replace(/"/g,"'") is "<?xml version='1.0'?><root><test/></root>"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/dom-parse-serialize-xmldecl.html (0 => 114059)
--- trunk/LayoutTests/fast/dom/dom-parse-serialize-xmldecl.html (rev 0)
+++ trunk/LayoutTests/fast/dom/dom-parse-serialize-xmldecl.html 2012-04-13 00:58:30 UTC (rev 114059)
@@ -0,0 +1,38 @@
+<html>
+ <script src=""
+ <script type="text/_javascript_">
+ description("This test verifies that the xml declaration gets serialized if present.");
+
+ var xmlpi = '<?xml version="1.0" encoding="UTF-8"?>';
+ var markup = xmlpi + '<root><test/></root>';
+ var xmldoc = new DOMParser().parseFromString(markup, "text/xml");
+ shouldBeEqualToString("new XMLSerializer().serializeToString(xmldoc).replace(/\"/g,\"'\")", "<?xml version='1.0' encoding='UTF-8'?><root><test/></root>");
+
+ xmlpi = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
+ markup = xmlpi + '<root><test/></root>';
+ xmldoc = new DOMParser().parseFromString(markup, "text/xml");
+ shouldBeEqualToString("new XMLSerializer().serializeToString(xmldoc).replace(/\"/g,\"'\")", "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><root><test/></root>");
+
+ xmlpi = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>';
+ markup = xmlpi + '<root><test/></root>';
+ xmldoc = new DOMParser().parseFromString(markup, "text/xml");
+ shouldBeEqualToString("new XMLSerializer().serializeToString(xmldoc).replace(/\"/g,\"'\")", "<?xml version='1.0' encoding='UTF-8' standalone='no'?><root><test/></root>");
+
+ xmlpi = '<?xml version="1.0" standalone="yes"?>';
+ markup = xmlpi + '<root><test/></root>';
+ xmldoc = new DOMParser().parseFromString(markup, "text/xml");
+ shouldBeEqualToString("new XMLSerializer().serializeToString(xmldoc).replace(/\"/g,\"'\")", "<?xml version='1.0' standalone='yes'?><root><test/></root>");
+
+ xmlpi = '<?xml version="1.0" standalone="no"?>';
+ markup = xmlpi + '<root><test/></root>';
+ xmldoc = new DOMParser().parseFromString(markup, "text/xml");
+ shouldBeEqualToString("new XMLSerializer().serializeToString(xmldoc).replace(/\"/g,\"'\")", "<?xml version='1.0' standalone='no'?><root><test/></root>");
+
+ xmlpi = '<?xml version="1.0"?>';
+ markup = xmlpi + '<root><test/></root>';
+ xmldoc = new DOMParser().parseFromString(markup, "text/xml");
+ shouldBeEqualToString("new XMLSerializer().serializeToString(xmldoc).replace(/\"/g,\"'\")", "<?xml version='1.0'?><root><test/></root>");
+
+ </script>
+ <script src=""
+</html>
Modified: trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-get-expected.txt (114058 => 114059)
--- trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-get-expected.txt 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-get-expected.txt 2012-04-13 00:58:30 UTC (rev 114059)
@@ -10,7 +10,7 @@
<d id="id3">Three</d>
</doc>
responseXML serialized
-<!DOCTYPE doc><doc>
+<?xml version="1.0"?><!DOCTYPE doc><doc>
<foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>
<d id="id3">Three</d>
</doc>
Modified: trunk/LayoutTests/fast/xsl/xslt-processor-expected.txt (114058 => 114059)
--- trunk/LayoutTests/fast/xsl/xslt-processor-expected.txt 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/LayoutTests/fast/xsl/xslt-processor-expected.txt 2012-04-13 00:58:30 UTC (rev 114059)
@@ -1,7 +1,7 @@
0.1 original xml:
-<?xml-stylesheet type="text/xsl" href="" XML: <<<&тест&>>></TEST>
+<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="" XML: <<<&тест&>>></TEST>
0.2 xsl1:
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="KOI8-R"/>
<xsl:template match="TEST">CHARACTERS IN XSLT: <<<&тест&>>>
@@ -14,7 +14,7 @@
</xsl:stylesheet>
0.3 xsl2:
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="TEST">
<html xmlns="http://www.w3.org/1999/xhtml">
@@ -39,7 +39,7 @@
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>
CHARACTERS IN XSLT: ééééééééééé <br><br>SOURCE XML: <<<&тест&>>></body></html>
1.2 Import same stylesheet twice:
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title></head>
<body>
<pre>CHARACTERS IN XSLT: <<<&тест&>>>
Modified: trunk/LayoutTests/http/tests/xmlhttprequest/xml-encoding-expected.txt (114058 => 114059)
--- trunk/LayoutTests/http/tests/xmlhttprequest/xml-encoding-expected.txt 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/xml-encoding-expected.txt 2012-04-13 00:58:30 UTC (rev 114059)
@@ -5,4 +5,4 @@
responseXML.xmlEncoding: windows-1251
responseXML.xmlVersion: 1.0
responseXML.xmlStandalone: true
-Request body: <doc>Проверка</doc>
+Request body: <?xml version="1.0" encoding="windows-1251" standalone="yes"?><doc>Проверка</doc>
Modified: trunk/LayoutTests/platform/chromium-mac/fast/xmlhttprequest/xmlhttprequest-get-expected.txt (114058 => 114059)
--- trunk/LayoutTests/platform/chromium-mac/fast/xmlhttprequest/xmlhttprequest-get-expected.txt 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/LayoutTests/platform/chromium-mac/fast/xmlhttprequest/xmlhttprequest-get-expected.txt 2012-04-13 00:58:30 UTC (rev 114059)
@@ -10,7 +10,7 @@
<d id="id3">Three</d>
</doc>
responseXML serialized
-<!DOCTYPE doc><doc>
+<?xml version="1.0"?><!DOCTYPE doc><doc>
<foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>
<d id="id3">Three</d>
</doc>
Modified: trunk/LayoutTests/platform/chromium-win/fast/xmlhttprequest/xmlhttprequest-get-expected.txt (114058 => 114059)
--- trunk/LayoutTests/platform/chromium-win/fast/xmlhttprequest/xmlhttprequest-get-expected.txt 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/LayoutTests/platform/chromium-win/fast/xmlhttprequest/xmlhttprequest-get-expected.txt 2012-04-13 00:58:30 UTC (rev 114059)
@@ -10,7 +10,7 @@
<d id="id3">Three</d>
</doc>
responseXML serialized
-<!DOCTYPE doc><doc>
+<?xml version="1.0"?><!DOCTYPE doc><doc>
<foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>
<d id="id3">Three</d>
</doc>
Modified: trunk/Source/WebCore/ChangeLog (114058 => 114059)
--- trunk/Source/WebCore/ChangeLog 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/Source/WebCore/ChangeLog 2012-04-13 00:58:30 UTC (rev 114059)
@@ -1,3 +1,34 @@
+2012-04-12 Rob Buis <[email protected]>
+
+ XMLSerializer().serializeToString() doesn't generate the XML declaration markup like Opera and Firefox
+ https://bugs.webkit.org/show_bug.cgi?id=83432
+
+ Reviewed by Ryosuke Niwa.
+
+ Serialize the xml declaration exactly as parsed, if present in the document.
+
+ Test: fast/dom/dom-parse-serialize-xmldecl.html
+
+ * dom/Document.cpp:
+ (WebCore::Document::Document):
+ (WebCore::Document::setXMLStandalone): update xmlStandalone to either yes or no.
+ * dom/Document.h:
+ (WebCore::Document::xmlStandalone):
+ (WebCore::Document::xmlStandaloneStatus): xmlStandalone can be unspecified, yes or no.
+ (WebCore::Document::hasXMLDeclaration): test if xml declaration is present.
+ (WebCore::Document::setHasXMLDeclaration):
+ (Document):
+ * editing/MarkupAccumulator.cpp:
+ (WebCore::MarkupAccumulator::appendXMLDeclaration): write xml declaration if present.
+ (WebCore):
+ (WebCore::MarkupAccumulator::appendStartMarkup):
+ * editing/MarkupAccumulator.h:
+ (MarkupAccumulator):
+ * xml/parser/XMLDocumentParserLibxml2.cpp:
+ (WebCore::XMLDocumentParser::startDocument): call setHasXmlDeclaration and any declaration strings parsed.
+ * xml/parser/XMLDocumentParserQt.cpp:
+ (WebCore::XMLDocumentParser::startDocument): call setHasXmlDeclaration and any declaration strings parsed.
+
2012-04-12 Adam Barth <[email protected]>
window.open should prepare for seamless navigation by using findFrameForNavigation
Modified: trunk/Source/WebCore/dom/Document.cpp (114058 => 114059)
--- trunk/Source/WebCore/dom/Document.cpp 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/Source/WebCore/dom/Document.cpp 2012-04-13 00:58:30 UTC (rev 114059)
@@ -441,7 +441,8 @@
, m_overMinimumLayoutThreshold(false)
, m_scriptRunner(ScriptRunner::create(this))
, m_xmlVersion("1.0")
- , m_xmlStandalone(false)
+ , m_xmlStandalone(StandaloneUnspecified)
+ , m_hasXMLDeclaration(0)
, m_savedRenderer(0)
, m_designMode(inherit)
#if ENABLE(DASHBOARD_SUPPORT)
@@ -1197,7 +1198,7 @@
return;
}
- m_xmlStandalone = standalone;
+ m_xmlStandalone = standalone ? Standalone : NotStandalone;
}
void Document::setDocumentURI(const String& uri)
Modified: trunk/Source/WebCore/dom/Document.h (114058 => 114059)
--- trunk/Source/WebCore/dom/Document.h 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/Source/WebCore/dom/Document.h 2012-04-13 00:58:30 UTC (rev 114059)
@@ -395,11 +395,15 @@
String xmlEncoding() const { return m_xmlEncoding; }
String xmlVersion() const { return m_xmlVersion; }
- bool xmlStandalone() const { return m_xmlStandalone; }
+ enum StandaloneStatus { StandaloneUnspecified, Standalone, NotStandalone };
+ bool xmlStandalone() const { return m_xmlStandalone == Standalone; }
+ StandaloneStatus xmlStandaloneStatus() const { return static_cast<StandaloneStatus>(m_xmlStandalone); }
+ bool hasXMLDeclaration() const { return m_hasXMLDeclaration; }
void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser
void setXMLVersion(const String&, ExceptionCode&);
void setXMLStandalone(bool, ExceptionCode&);
+ void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration ? 1 : 0; }
String documentURI() const { return m_documentURI; }
void setDocumentURI(const String&);
@@ -1374,7 +1378,8 @@
String m_xmlEncoding;
String m_xmlVersion;
- bool m_xmlStandalone;
+ unsigned m_xmlStandalone : 2;
+ unsigned m_hasXMLDeclaration : 1;
String m_contentLanguage;
Modified: trunk/Source/WebCore/editing/MarkupAccumulator.cpp (114058 => 114059)
--- trunk/Source/WebCore/editing/MarkupAccumulator.cpp 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/Source/WebCore/editing/MarkupAccumulator.cpp 2012-04-13 00:58:30 UTC (rev 114059)
@@ -296,6 +296,36 @@
result.append(commentEnd, sizeof(commentEnd) - 1);
}
+void MarkupAccumulator::appendXMLDeclaration(StringBuilder& result, const Document* document)
+{
+ if (!document->hasXMLDeclaration())
+ return;
+
+ static const char xmlDeclStart[] = "<?xml version=\"";
+ result.append(xmlDeclStart, sizeof(xmlDeclStart) - 1);
+ result.append(document->xmlVersion());
+ const String& encoding = document->xmlEncoding();
+ if (!encoding.isEmpty()) {
+ static const char xmlEncoding[] = "\" encoding=\"";
+ result.append(xmlEncoding, sizeof(xmlEncoding) - 1);
+ result.append(encoding);
+ }
+ if (document->xmlStandaloneStatus() != Document::StandaloneUnspecified) {
+ static const char xmlStandalone[] = "\" standalone=\"";
+ result.append(xmlStandalone, sizeof(xmlStandalone) - 1);
+ if (document->xmlStandalone()) {
+ static const char standaloneYes[] = "yes";
+ result.append(standaloneYes, sizeof(standaloneYes) - 1);
+ } else {
+ static const char standaloneNo[] = "no";
+ result.append(standaloneNo, sizeof(standaloneNo) - 1);
+ }
+ }
+
+ static const char xmlDeclEnd[] = "\"?>";
+ result.append(xmlDeclEnd, sizeof(xmlDeclEnd) - 1);
+}
+
void MarkupAccumulator::appendDocumentType(StringBuilder& result, const DocumentType* n)
{
if (n->name().isEmpty())
@@ -424,6 +454,8 @@
appendComment(result, static_cast<const Comment*>(node)->data());
break;
case Node::DOCUMENT_NODE:
+ appendXMLDeclaration(result, static_cast<const Document*>(node));
+ break;
case Node::DOCUMENT_FRAGMENT_NODE:
break;
case Node::DOCUMENT_TYPE_NODE:
Modified: trunk/Source/WebCore/editing/MarkupAccumulator.h (114058 => 114059)
--- trunk/Source/WebCore/editing/MarkupAccumulator.h 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/Source/WebCore/editing/MarkupAccumulator.h 2012-04-13 00:58:30 UTC (rev 114059)
@@ -89,6 +89,7 @@
void appendNamespace(StringBuilder&, const AtomicString& prefix, const AtomicString& namespaceURI, Namespaces&);
EntityMask entityMaskForText(Text*) const;
virtual void appendText(StringBuilder&, Text*);
+ void appendXMLDeclaration(StringBuilder&, const Document*);
void appendDocumentType(StringBuilder&, const DocumentType*);
void appendProcessingInstruction(StringBuilder&, const String& target, const String& data);
virtual void appendElement(StringBuilder&, Element*, Namespaces*);
Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp (114058 => 114059)
--- trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp 2012-04-13 00:58:30 UTC (rev 114059)
@@ -1010,15 +1010,28 @@
newNode->attach();
}
+enum StandaloneInfo {
+ StandaloneUnspecified = -2,
+ NoXMlDeclaration,
+ StandaloneNo,
+ StandaloneYes
+};
+
void XMLDocumentParser::startDocument(const xmlChar* version, const xmlChar* encoding, int standalone)
{
- ExceptionCode ec = 0;
+ StandaloneInfo standaloneInfo = (StandaloneInfo)standalone;
+ if (standaloneInfo == NoXMlDeclaration) {
+ document()->setHasXMLDeclaration(false);
+ return;
+ }
if (version)
- document()->setXMLVersion(toString(version), ec);
- document()->setXMLStandalone(standalone == 1, ec); // possible values are 0, 1, and -1
+ document()->setXMLVersion(toString(version), ASSERT_NO_EXCEPTION);
+ if (standalone != StandaloneUnspecified)
+ document()->setXMLStandalone(standaloneInfo == StandaloneYes, ASSERT_NO_EXCEPTION);
if (encoding)
document()->setXMLEncoding(toString(encoding));
+ document()->setHasXMLDeclaration(true);
}
void XMLDocumentParser::endDocument()
Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParserQt.cpp (114058 => 114059)
--- trunk/Source/WebCore/xml/parser/XMLDocumentParserQt.cpp 2012-04-13 00:52:06 UTC (rev 114058)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParserQt.cpp 2012-04-13 00:58:30 UTC (rev 114059)
@@ -422,6 +422,7 @@
QStringRef encoding = m_stream.documentEncoding();
if (!encoding.isEmpty())
document()->setXMLEncoding(encoding);
+ document()->setHasXMLDeclaration(!version.isEmpty());
}
}