From: Miss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>
Date: Sat, 3 Oct 2020 06:42:38 +0000 (-0700)
Subject: bpo-41900: C14N 2.0 serialisation failed for unprefixed attributes when a default...
X-Git-Tag: v3.8.7rc1~143
X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cfed5343331350c5737b464970a31f7588319e8b;p=thirdparty%2FPython%2Fcpython.git
bpo-41900: C14N 2.0 serialisation failed for unprefixed attributes when a default namespace was defined. (GH-22474) (GH-22508)
(cherry picked from commit 6a412c94b6b68e7e3632562dc7358a12ffd1447f)
---
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index b2492cda848f..341a3c7cd766 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -3701,6 +3701,14 @@ class C14NTest(unittest.TestCase):
#self.assertEqual(c14n_roundtrip(""),
#'')
+ # Namespace issues
+ xml = ''
+ self.assertEqual(c14n_roundtrip(xml), xml)
+ xml = ''
+ self.assertEqual(c14n_roundtrip(xml), xml)
+ xml = ''
+ self.assertEqual(c14n_roundtrip(xml), xml)
+
def test_c14n_exclusion(self):
xml = textwrap.dedent("""\
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 645e999a0be6..598b569ea958 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1849,6 +1849,11 @@ class C14NWriterTarget:
self._declared_ns_stack[-1].append((uri, prefix))
return f'{prefix}:{tag}' if prefix else tag, tag, uri
+ if not uri:
+ # As soon as a default namespace is defined,
+ # anything that has no namespace (and thus, no prefix) goes there.
+ return tag, tag, uri
+
raise ValueError(f'Namespace "{uri}" is not declared in scope')
def data(self, data):
diff --git a/Misc/NEWS.d/next/Library/2020-10-01-10-50-12.bpo-41900.Cho7oh.rst b/Misc/NEWS.d/next/Library/2020-10-01-10-50-12.bpo-41900.Cho7oh.rst
new file mode 100644
index 000000000000..6586c09ec985
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-10-01-10-50-12.bpo-41900.Cho7oh.rst
@@ -0,0 +1,2 @@
+C14N 2.0 serialisation in xml.etree.ElementTree failed for unprefixed attributes
+when a default namespace was defined.