fix: refuse an unparseable platform original

This commit is contained in:
Abdessamad Derraz committed 2026-10-18 14:57:28 +02:00
1 parent be0443a935
commit 213d19ed27
3 files changed
+36 -4

No files matched your search

+7 -2
View File
@@ -131,8 +131,13 @@ class Exporter(BaseExporter):
if original:
try:
root = parse_untrusted_xml(original, self.native_filename(), comments=True)
except (ParseError, ValueError):
root = None
except (ParseError, ValueError) as exc:
# Rebuilt from our model alone, the export would drop every
# system we do not transcribe and the maintainer's comments.
raise ValueError(
f"Recalbox's {self.native_filename()} does not parse ({exc}); "
"fetch it again with --refresh-cache"
) from exc
if root is not None:
theirs = [
(s.get("platform", ""), s.get("fullname", ""), [
+5 -2
View File
@@ -69,8 +69,11 @@ class Exporter(BaseExporter):
if original:
try:
base = json.loads(original, object_pairs_hook=OrderedDict)
except json.JSONDecodeError:
base = {}
except json.JSONDecodeError as exc:
raise ValueError(
f"RetroBat's {self.native_filename()} does not parse ({exc}); "
"fetch it again with --refresh-cache"
) from exc
exportable = {
system.native_id: (system, files)
+24
View File
@@ -762,5 +762,29 @@ class AStaleTruthIsRefused(unittest.TestCase):
export_native.load_inputs("retropie", truth_dir, str(root / "platforms"))
class ACorruptOriginalIsRefused(unittest.TestCase):
"""A truncated es_bios.xml in the cache was ignored: the export was
rebuilt from our model alone, losing the systems we do not transcribe
and the maintainer's comments, and the run ended in success."""
def test_recalbox_refuses_it(self):
fe = NativeFile("bios.bin", "bios.bin", "nes", platform={"md5": A})
exporter = Recalbox()
with self.assertRaises(ValueError) as caught:
exporter.render({"nes": NativeSystem("nes", files=[fe])}, None,
{exporter.native_filename(): "<biosList><system platform="})
self.assertIn("does not parse", str(caught.exception))
def test_retrobat_refuses_it(self):
from exporter.retrobat_exporter import Exporter as RetroBat # noqa: PLC0415
fe = NativeFile("bios.bin", "bios.bin", "nes", platform={"md5": A})
exporter = RetroBat()
with self.assertRaises(ValueError):
exporter.render({"nes": NativeSystem("nes", files=[fe])}, None,
{exporter.native_filename(): '{"nes": {'})
if __name__ == "__main__":
unittest.main()