diff options
author | RainerHausdorf <rainer.hausdorf@scale.eu> | 2019-08-18 12:35:15 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2019-08-18 12:35:15 +0200 |
commit | db8519a525b07d2501c8b6193b2224f52bc7d350 (patch) | |
tree | 956d8d89e44a218d7e76fc93cc0eb224d2f46031 /src/lxml/tests | |
parent | c9d4316b57c44b14998ddd3ca3a11859d935ee6f (diff) | |
download | python-lxml-db8519a525b07d2501c8b6193b2224f52bc7d350.tar.gz |
Fix false detection of recursive include (GH-286)
Fix false detection of recursive include.
In some cases ElementInclude does raise FatalIncludeError because of
recursive include detection. This is the case if the same file gets
included multiple times, but not recursive.
This is a fix for https://bugs.launchpad.net/lxml/+bug/1835708
Diffstat (limited to 'src/lxml/tests')
-rw-r--r-- | src/lxml/tests/test_etree.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/lxml/tests/test_etree.py b/src/lxml/tests/test_etree.py index fa1e4bd3..cab5900a 100644 --- a/src/lxml/tests/test_etree.py +++ b/src/lxml/tests/test_etree.py @@ -4471,6 +4471,46 @@ class ElementIncludeTestCase(_XIncludeTestCase): </document> """ + XINCLUDE["NonRecursive1.xml"] = """\ + <?xml version='1.0'?> + <document xmlns:xi="http://www.w3.org/2001/XInclude"> + <p>The following is multiple times the source code of NonRecursive3.xml:</p> + <xi:include href="NonRecursive3.xml"/> + <xi:include href="NonRecursive3.xml"/> + <p>The following is multiple times the source code of Leaf.xml:</p> + <xi:include href="Leaf.xml"/> + <xi:include href="Leaf.xml"/> + <xi:include href="Leaf.xml"/> + <p>One more time the source code of NonRecursive3.xml:</p> + <xi:include href="NonRecursive3.xml"/> + </document> + """ + + XINCLUDE["NonRecursive2.xml"] = """\ + <?xml version='1.0'?> + <document xmlns:xi="http://www.w3.org/2001/XInclude"> + <p>The following is multiple times the source code of NonRecursive3.xml:</p> + <xi:include href="NonRecursive3.xml"/> + <xi:include href="NonRecursive3.xml"/> + </document> + """ + + XINCLUDE["NonRecursive3.xml"] = """\ + <?xml version='1.0'?> + <document xmlns:xi="http://www.w3.org/2001/XInclude"> + <p>The following is multiple times the source code of Leaf.xml:</p> + <xi:include href="Leaf.xml"/> + <xi:include href="Leaf.xml"/> + </document> + """ + + XINCLUDE["Leaf.xml"] = """\ + <?xml version='1.0'?> + <document xmlns:xi="http://www.w3.org/2001/XInclude"> + <p>No further includes</p> + </document> + """ + def xinclude_loader(self, href, parse="xml", encoding=None): try: data = textwrap.dedent(self.XINCLUDE[href]) @@ -4519,6 +4559,20 @@ class ElementIncludeTestCase(_XIncludeTestCase): self.assertEqual(str(cm.exception), "recursive include of 'Recursive2.xml' detected") + def test_multiple_include_of_same_file(self): + # Test that including the same file multiple times, but on the same level + # is not detected as recursive include + document = self.xinclude_loader("NonRecursive3.xml").getroottree() + self.include(document, self.xinclude_loader) + + # same but for more than one level + document = self.xinclude_loader("NonRecursive1.xml").getroottree() + self.include(document, self.xinclude_loader) + + # same but no Leaf.xml in top-level file + document = self.xinclude_loader("NonRecursive2.xml").getroottree() + self.include(document, self.xinclude_loader) + class ETreeC14NTestCase(HelperTestCase): def test_c14n(self): |