- Revision
- 153508
- Author
- [email protected]
- Date
- 2013-07-30 18:59:00 -0700 (Tue, 30 Jul 2013)
Log Message
XMLSerializer should reset default namespace when necessary
https://bugs.webkit.org/show_bug.cgi?id=16739
XMLSerializer's handling of namespaces seems to be pretty broken
https://bugs.webkit.org/show_bug.cgi?id=106531
Reviewed by Ryosuke Niwa.
Source/WebCore:
Write out empty default namespace declaration if the element is not in any namespace, as
described in http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syntax.html#xml-fragment-serialization-algorithm.
Tests: fast/dom/XMLSerializer-element-empty-namespace.html
fast/dom/XMLSerializer-element-empty-namespace2.html
* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::appendNamespace):
(WebCore::MarkupAccumulator::appendOpenTag):
* editing/MarkupAccumulator.h:
LayoutTests:
Add tests based on the testcases of both bugs.
* fast/dom/XMLSerializer-element-empty-namespace-expected.txt: Added.
* fast/dom/XMLSerializer-element-empty-namespace.html: Added.
* fast/dom/XMLSerializer-element-empty-namespace2-expected.txt: Added.
* fast/dom/XMLSerializer-element-empty-namespace2.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (153507 => 153508)
--- trunk/LayoutTests/ChangeLog 2013-07-31 01:50:16 UTC (rev 153507)
+++ trunk/LayoutTests/ChangeLog 2013-07-31 01:59:00 UTC (rev 153508)
@@ -1,3 +1,19 @@
+2013-07-30 Rob Buis <[email protected]>
+
+ XMLSerializer should reset default namespace when necessary
+ https://bugs.webkit.org/show_bug.cgi?id=16739
+ XMLSerializer's handling of namespaces seems to be pretty broken
+ https://bugs.webkit.org/show_bug.cgi?id=106531
+
+ Reviewed by Ryosuke Niwa.
+
+ Add tests based on the testcases of both bugs.
+
+ * fast/dom/XMLSerializer-element-empty-namespace-expected.txt: Added.
+ * fast/dom/XMLSerializer-element-empty-namespace.html: Added.
+ * fast/dom/XMLSerializer-element-empty-namespace2-expected.txt: Added.
+ * fast/dom/XMLSerializer-element-empty-namespace2.html: Added.
+
2013-07-30 Alexey Proskuryakov <[email protected]>
REGRESSION: Crash when opening a message on Gmail
Added: trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace-expected.txt (0 => 153508)
--- trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace-expected.txt 2013-07-31 01:59:00 UTC (rev 153508)
@@ -0,0 +1,3 @@
+This tests that XMLSerializer.serializeToString() correctly writes out an empty default namespace declaration if the element is not in any namespace.
+<div xmlns="http://www.w3.org/1999/xhtml" id="target"> <div id="output"> </div><a xmlns="" href=""
+
Added: trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace.html (0 => 153508)
--- trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace.html (rev 0)
+++ trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace.html 2013-07-31 01:59:00 UTC (rev 153508)
@@ -0,0 +1,29 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <script type="text/_javascript_">
+ function runTest()
+ {
+ if (window.testRunner)
+ testRunner.dumpAsText();
+
+ var target = document.getElementById("target");
+
+ var a = document.createElementNS("", "a");
+ a.setAttribute('href', '#');
+
+ target.appendChild(a);
+
+ var serializer = new XMLSerializer();
+ var xmlString = serializer.serializeToString(target);
+
+ var outputText = document.getElementById("output");
+ outputText.textContent = xmlString;
+ }
+ </script>
+</head>
+ <body _onload_="runTest()">
+This tests that XMLSerializer.serializeToString() correctly writes out an empty default namespace declaration if the element is not in any namespace.
+ <div id="target"/>
+ <div id="output"/>
+ </body>
+</html>
Added: trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace2-expected.txt (0 => 153508)
--- trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace2-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace2-expected.txt 2013-07-31 01:59:00 UTC (rev 153508)
@@ -0,0 +1,2 @@
+This tests that XMLSerializer.serializeToString() correctly writes out an empty default namespace declaration if the element is not in any namespace.
+<x xmlns="foo"><y xmlns=""/></x>
Added: trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace2.html (0 => 153508)
--- trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace2.html (rev 0)
+++ trunk/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace2.html 2013-07-31 01:59:00 UTC (rev 153508)
@@ -0,0 +1,26 @@
+<html>
+<head>
+ <script type="text/_javascript_">
+ function runTest()
+ {
+ if (window.testRunner)
+ testRunner.dumpAsText();
+
+ var doc = document.implementation.createDocument("foo", "x", null);
+ var parent = doc.firstChild;
+ var kid = doc.createElementNS(null, "y");
+ parent.appendChild(kid);
+ var serializer = new XMLSerializer();
+ var xmlString = serializer.serializeToString(doc);
+
+ var outputText = document.getElementById("output");
+ outputText.textContent = xmlString;
+ }
+ </script>
+</head>
+ <body _onload_="runTest()">
+This tests that XMLSerializer.serializeToString() correctly writes out an empty default namespace declaration if the element is not in any namespace.
+ <div id="target"/>
+ <div id="output"/>
+ </body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (153507 => 153508)
--- trunk/Source/WebCore/ChangeLog 2013-07-31 01:50:16 UTC (rev 153507)
+++ trunk/Source/WebCore/ChangeLog 2013-07-31 01:59:00 UTC (rev 153508)
@@ -1,3 +1,23 @@
+2013-07-30 Rob Buis <[email protected]>
+
+ XMLSerializer should reset default namespace when necessary
+ https://bugs.webkit.org/show_bug.cgi?id=16739
+ XMLSerializer's handling of namespaces seems to be pretty broken
+ https://bugs.webkit.org/show_bug.cgi?id=106531
+
+ Reviewed by Ryosuke Niwa.
+
+ Write out empty default namespace declaration if the element is not in any namespace, as
+ described in http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syntax.html#xml-fragment-serialization-algorithm.
+
+ Tests: fast/dom/XMLSerializer-element-empty-namespace.html
+ fast/dom/XMLSerializer-element-empty-namespace2.html
+
+ * editing/MarkupAccumulator.cpp:
+ (WebCore::MarkupAccumulator::appendNamespace):
+ (WebCore::MarkupAccumulator::appendOpenTag):
+ * editing/MarkupAccumulator.h:
+
2013-07-30 Chris Fleizach <[email protected]>
Don't post accessibility notification on object in detached document.
Modified: trunk/Source/WebCore/editing/MarkupAccumulator.cpp (153507 => 153508)
--- trunk/Source/WebCore/editing/MarkupAccumulator.cpp 2013-07-31 01:50:16 UTC (rev 153507)
+++ trunk/Source/WebCore/editing/MarkupAccumulator.cpp 2013-07-31 01:59:00 UTC (rev 153508)
@@ -293,11 +293,18 @@
return true;
}
-void MarkupAccumulator::appendNamespace(StringBuilder& result, const AtomicString& prefix, const AtomicString& namespaceURI, Namespaces& namespaces)
+void MarkupAccumulator::appendNamespace(StringBuilder& result, const AtomicString& prefix, const AtomicString& namespaceURI, Namespaces& namespaces, bool allowEmptyDefaultNS)
{
namespaces.checkConsistency();
- if (namespaceURI.isEmpty())
+ if (namespaceURI.isEmpty()) {
+ // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syntax.html#xml-fragment-serialization-algorithm
+ if (allowEmptyDefaultNS && namespaces.get(emptyAtom.impl())) {
+ result.append(' ');
+ result.append(xmlnsAtom.string());
+ result.appendLiteral("=\"\"");
+ }
return;
+ }
// Use emptyAtoms's impl() for both null and empty strings since the HashMap can't handle 0 as a key
AtomicStringImpl* pre = prefix.isEmpty() ? emptyAtom.impl() : prefix.impl();
@@ -439,7 +446,7 @@
}
result.append(element->nodeNamePreservingCase());
if ((inXMLFragmentSerialization() || !element->document()->isHTMLDocument()) && namespaces && shouldAddNamespaceElement(element))
- appendNamespace(result, element->prefix(), element->namespaceURI(), *namespaces);
+ appendNamespace(result, element->prefix(), element->namespaceURI(), *namespaces, inXMLFragmentSerialization());
}
void MarkupAccumulator::appendCloseTag(StringBuilder& result, Element* element)
Modified: trunk/Source/WebCore/editing/MarkupAccumulator.h (153507 => 153508)
--- trunk/Source/WebCore/editing/MarkupAccumulator.h 2013-07-31 01:50:16 UTC (rev 153507)
+++ trunk/Source/WebCore/editing/MarkupAccumulator.h 2013-07-31 01:59:00 UTC (rev 153508)
@@ -88,7 +88,7 @@
void appendNodeValue(StringBuilder&, const Node*, const Range*, EntityMask);
bool shouldAddNamespaceElement(const Element*);
bool shouldAddNamespaceAttribute(const Attribute&, Namespaces&);
- void appendNamespace(StringBuilder&, const AtomicString& prefix, const AtomicString& namespaceURI, Namespaces&);
+ void appendNamespace(StringBuilder&, const AtomicString& prefix, const AtomicString& namespaceURI, Namespaces&, bool allowEmptyDefaultNS = false);
EntityMask entityMaskForText(Text*) const;
virtual void appendText(StringBuilder&, Text*);
void appendXMLDeclaration(StringBuilder&, const Document*);