Skip to content

Commit c77ff03

Browse files
tkent-googleMarcos Cáceres
authored and
Marcos Cáceres
committed
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 behavior 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1516124 Reviewed-by: Yoshifumi Inoue <[email protected]> Commit-Queue: Kent Tamura <[email protected]> Auto-Submit: Kent Tamura <[email protected]> Cr-Commit-Position: refs/heads/master@{#639873}
1 parent 13d6b07 commit c77ff03

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

domparsing/XMLSerializer-serializeToString.html

+9-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ <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><child xmlns=""/></root>')),
50+
'<root><child/></root>');
51+
assert_equals(serialize(parse('<root xmlns=""><child xmlns=""/></root>')),
52+
'<root><child/></root>');
53+
assert_equals(serialize(parse('<root xmlns="u1"><child xmlns="u1"/></root>')),
54+
'<root xmlns="u1"><child/></root>');
55+
}, 'Check if redundant xmlns="..." is dropped.');
56+
4857
test(function() {
4958
const root = parse('<root xmlns="uri1"/>');
5059
const child = root.ownerDocument.createElement('child');
@@ -145,8 +154,6 @@ <h1>domparsing_XMLSerializer_serializeToString</h1>
145154

146155
test(function() {
147156
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>');
150157
assert_equals(serialize(parse('<root xmlns="u1"><p:child xmlns:p="u1"/></root>')), '<root xmlns="u1"><child xmlns:p="u1"/></root>');
151158
}, 'Check if start tag serialization drops element prefix if the namespace is same as inherited default namespace.');
152159

0 commit comments

Comments
 (0)