From 7393f6bc414ae5d140101fffcb48148a36b80f64 Mon Sep 17 00:00:00 2001 From: Chris Allen Date: Fri, 20 Oct 2023 16:35:39 +0100 Subject: [PATCH] manifest_xml: Fix empty project list when DOCTYPE is present When parsing the manifest XML, the code looks for a top level DOM node named "manifest". However, it doesn't check that it's an element type node so if there is also an XML document type declaration node present (which has the same name as the root element) then it selects the wrong node and hence you end up with no projects defined at all. Change-Id: I8d101caffbbc2a06e56136ff21302e3f09cfc96b Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/390357 Reviewed-by: Mike Frysinger Tested-by: Chris Allen Commit-Queue: Chris Allen --- manifest_xml.py | 5 ++++- tests/test_manifest_xml.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/manifest_xml.py b/manifest_xml.py index 03925176..0068ac6a 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -1266,7 +1266,10 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md raise ManifestParseError("no root node in %s" % (path,)) for manifest in root.childNodes: - if manifest.nodeName == "manifest": + if ( + manifest.nodeType == manifest.ELEMENT_NODE + and manifest.nodeName == "manifest" + ): break else: raise ManifestParseError("no in %s" % (path,)) diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 1015e114..bd255dcc 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py @@ -385,6 +385,21 @@ class XmlManifestTests(ManifestParseTestCase): "", ) + def test_parse_with_xml_doctype(self): + """Check correct manifest parse with DOCTYPE node present.""" + manifest = self.getXmlManifest( + """ + + + + + + +""" + ) + self.assertEqual(len(manifest.projects), 1) + self.assertEqual(manifest.projects[0].name, "test-project") + class IncludeElementTests(ManifestParseTestCase): """Tests for ."""