gamedata_graph: keep scanning after an unsupported XML encoding (#6765)

Squash-merged after diff review of PR #6765 - gamedata_graph: keep scanning after an unsupported XML encoding
This commit is contained in:
Solthodox
2026-11-23 17:05:27 +01:00
committed by GitHub
parent b227b866a4
commit c2d7dea381
3 changed files with 23 additions and 3 deletions

View File

@ -8,7 +8,8 @@ name or target path is committed.
`tools/gamedata_graph.py` rebuilds the documents with `gamedata_index.py` and
`gamedata_xml.load_documents`, then keeps the reference strings long enough to join them. It is
standard-library only and reads the same carve as the index and catalog.
standard-library only and reads the same carve as the index and catalog. XML with an unsupported
encoding counts as an unparsed payload; it supplies no edges and does not stop the other documents.
## Graph model

View File

@ -97,6 +97,24 @@ class GamedataGraphTest(unittest.TestCase):
return subprocess.run([sys.executable, "-I", TOOL, *args], cwd=self.root,
capture_output=True, text=True, errors="replace")
def test_unknown_encoding_counts_as_unparsed_beside_valid_document(self):
unsupported = os.path.join(self.root, "unsupported.xml")
valid = os.path.join(self.root, "valid.xml")
out = os.path.join(self.root, "graph.json")
with open(unsupported, "wb") as f:
f.write(b'<?xml version="1.0" encoding="x-fixture-unknown"?><Unparsed/>')
with open(valid, "wb") as f:
f.write(ALPHA)
result = self.run_tool(unsupported, valid, "--json", out)
self.assertEqual(result.returncode, 0, result.stderr)
with open(out, encoding="utf-8") as f:
summary = json.load(f)["summary"]
self.assertEqual(summary["payloads"], 2)
self.assertEqual(summary["parsed"], 1)
self.assertEqual(summary["unparsed"], 1)
self.assertEqual(summary["rootless"], 0)
self.assertEqual(summary["include_sites"], 2)
def test_cli_reports_unwritable_graph_report(self):
self.finish()
out = os.path.join(self.root, "missing", "graph.json")

View File

@ -118,9 +118,10 @@ def scan_document(doc: dict) -> dict:
"refs": [],
"includes": [],
}
data = doc["data"]
try:
root = ET.fromstring(doc["data"])
except (ET.ParseError, ValueError):
root = ET.fromstring(data)
except (ET.ParseError, ValueError, LookupError):
# A truncated tail can still carry a closing-root hint from the index. It is a named but
# unparsed document, not a rootless fragment; only an empty hint is rootless.
report["root"] = doc.get("root_hint") or ""