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 <vapier@google.com>
Tested-by: Chris Allen <chris.allen@arm.com>
Commit-Queue: Chris Allen <chris.allen@arm.com>
This commit is contained in:
Chris Allen 2023-10-20 16:35:39 +01:00 committed by LUCI
parent 8dd8521854
commit 7393f6bc41
2 changed files with 19 additions and 1 deletions

View File

@ -1266,7 +1266,10 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
raise ManifestParseError("no root node in %s" % (path,)) raise ManifestParseError("no root node in %s" % (path,))
for manifest in root.childNodes: for manifest in root.childNodes:
if manifest.nodeName == "manifest": if (
manifest.nodeType == manifest.ELEMENT_NODE
and manifest.nodeName == "manifest"
):
break break
else: else:
raise ManifestParseError("no <manifest> in %s" % (path,)) raise ManifestParseError("no <manifest> in %s" % (path,))

View File

@ -385,6 +385,21 @@ class XmlManifestTests(ManifestParseTestCase):
"</manifest>", "</manifest>",
) )
def test_parse_with_xml_doctype(self):
"""Check correct manifest parse with DOCTYPE node present."""
manifest = self.getXmlManifest(
"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE manifest []>
<manifest>
<remote name="test-remote" fetch="http://localhost" />
<default remote="test-remote" revision="refs/heads/main" />
<project name="test-project" path="src/test-project"/>
</manifest>
"""
)
self.assertEqual(len(manifest.projects), 1)
self.assertEqual(manifest.projects[0].name, "test-project")
class IncludeElementTests(ManifestParseTestCase): class IncludeElementTests(ManifestParseTestCase):
"""Tests for <include>.""" """Tests for <include>."""