Skip to content

Commit d1e20fc

Browse files
XMLSerializer: Keep redundant but harmless default namespace declarations
Since crrev.com/632142, XMLSerializer has dropped redundant xmlns="..." declarations. It matches to IE, Edge, and DOM P&S standard. This CL reverts the behaviro to unbreak existing applications. The restored behavior matches to Firefox and Safari. * MarkupAccumulator::AppendElement(): Even if ignore_namespace_definition_attribute_ is set, we drop a xmlns="..." only if its value is inconsistent with element's namespace. * MarkupAccumulator::AppendStartTagOpen(): if local_default_namespace is "" and ns is null, do not emit xmlns="". This avoids to serialize xmlns="" twice. Bug: w3c/DOM-Parsing#47 Bug: 940204 Change-Id: I2978ddc9a3f9511d227a9a1b902f1811ac1c3c07
1 parent b071158 commit d1e20fc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

domparsing/XMLSerializer-serializeToString.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ <h1>domparsing_XMLSerializer_serializeToString</h1>
4545
assert_equals(serialize(root), '<root xmlns="urn:bar"><outer xmlns=""><inner>value1</inner></outer></root>');
4646
}, 'Check if there is no redundant empty namespace declaration.');
4747

48+
test(function() {
49+
assert_equals(serialize(parse('<root xmlns=""><child xmlns=""/></root>')),
50+
'<root><child/></root>');
51+
assert_equals(serialize(parse('<root xmlns="u1"><child xmlns="u1"/></root>')),
52+
'<root xmlns="u1"><child/></root>');
53+
}, 'Check if redundant xmlns="..." is dropped.');
54+
4855
test(function() {
4956
const root = parse('<root xmlns="uri1"/>');
5057
const child = root.ownerDocument.createElement('child');
@@ -145,8 +152,6 @@ <h1>domparsing_XMLSerializer_serializeToString</h1>
145152

146153
test(function() {
147154
assert_equals(serialize(parse('<root><child/></root>')), '<root><child/></root>');
148-
assert_equals(serialize(parse('<root><child xmlns=""/></root>')), '<root><child/></root>');
149-
assert_equals(serialize(parse('<root xmlns="u1"><child xmlns="u1"/></root>')), '<root xmlns="u1"><child/></root>');
150155
assert_equals(serialize(parse('<root xmlns="u1"><p:child xmlns:p="u1"/></root>')), '<root xmlns="u1"><child xmlns:p="u1"/></root>');
151156
}, 'Check if start tag serialization drops element prefix if the namespace is same as inherited default namespace.');
152157

0 commit comments

Comments
 (0)