diff options
author | Felix C. Stegerman <flx@obfusk.net> | 2021-02-24 02:25:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-24 02:25:31 (GMT) |
commit | 1f433406bd46fbd00b88223ad64daea6bc9eaadc (patch) | |
tree | a02810a5aa293f957052638420626fec4f933d4b | |
parent | b9fe16a02717e89a2141311de1e36161af4de9a9 (diff) | |
download | cpython-1f433406bd46fbd00b88223ad64daea6bc9eaadc.zip cpython-1f433406bd46fbd00b88223ad64daea6bc9eaadc.tar.gz cpython-1f433406bd46fbd00b88223ad64daea6bc9eaadc.tar.bz2 |
bpo-42151: don't set specified_attributes=1 in pure Python ElementTree (GH-22987)
-rw-r--r-- | Lib/test/test_xml_etree.py | 19 | ||||
-rw-r--r-- | Lib/xml/etree/ElementTree.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-10-26-18-01-09.bpo-42151.et5f7s.rst | 3 |
3 files changed, 22 insertions, 2 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index fd4a385..fcb1f7f 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -108,6 +108,19 @@ EXTERNAL_ENTITY_XML = """\ <document>&entity;</document> """ +ATTLIST_XML = """\ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE Foo [ +<!ELEMENT foo (bar*)> +<!ELEMENT bar (#PCDATA)*> +<!ATTLIST bar xml:lang CDATA "eng"> +<!ENTITY qux "quux"> +]> +<foo> +<bar>&qux;</bar> +</foo> +""" + def checkwarnings(*filters, quiet=False): def decorator(test): def newtest(*args, **kwargs): @@ -1354,6 +1367,12 @@ class ElementTreeTest(unittest.TestCase): self.assertEqual(serialize(root, method='html'), '<cirriculum status="public" company="example"></cirriculum>') + def test_attlist_default(self): + # Test default attribute values; See BPO 42151. + root = ET.fromstring(ATTLIST_XML) + self.assertEqual(root[0].attrib, + {'{http://www.w3.org/XML/1998/namespace}lang': 'eng'}) + class XMLPullParserTest(unittest.TestCase): diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 7a26900..168418e 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1560,7 +1560,6 @@ class XMLParser: # Configure pyexpat: buffering, new-style attribute handling. parser.buffer_text = 1 parser.ordered_attributes = 1 - parser.specified_attributes = 1 self._doctype = None self.entity = {} try: @@ -1580,7 +1579,6 @@ class XMLParser: for event_name in events_to_report: if event_name == "start": parser.ordered_attributes = 1 - parser.specified_attributes = 1 def handler(tag, attrib_in, event=event_name, append=append, start=self._start): append((event, start(tag, attrib_in))) diff --git a/Misc/NEWS.d/next/Library/2020-10-26-18-01-09.bpo-42151.et5f7s.rst b/Misc/NEWS.d/next/Library/2020-10-26-18-01-09.bpo-42151.et5f7s.rst new file mode 100644 index 0000000..6361f2c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-10-26-18-01-09.bpo-42151.et5f7s.rst @@ -0,0 +1,3 @@ +Make the pure Python implementation of :mod:`xml.etree.ElementTree` behave +the same as the C implementation (:mod:`_elementree`) regarding default +attribute values (by not setting ``specified_attributes=1``). |