From 14499cdcccb619de29548feed0bd89b04c9d48f3 Mon Sep 17 00:00:00 2001 From: David Fischer Date: Sun, 13 Sep 2026 08:27:38 -0700 Subject: [PATCH] Unicode fix for Ratonhnhake:ton --- src/scryfall.py | 6 ++++++ tests/test_scryfall.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/scryfall.py b/src/scryfall.py index 40b7eca..9d6bf69 100644 --- a/src/scryfall.py +++ b/src/scryfall.py @@ -31,7 +31,11 @@ "Jotun Grunt": "Jötun Grunt", "Sol'kanar the Tainted": "Sol'Kanar the Tainted", "Furnace Of Rath": "Furnace of Rath", + "Lim-Dul's Vault": "Lim-Dûl's Vault", "Lim-Dûl's Vault": "Lim-Dûl's Vault", + # Ratonhnhaké꞉ton uses modifier letter colon (U+A789) in Scryfall, but ASCII colon in MTGO + "Ratonhnhaké:ton": "Ratonhnhaké꞉ton", + "Ratonhnhake:ton": "Ratonhnhaké꞉ton", } ALCHEMY_PREFIX = "A-" @@ -74,6 +78,8 @@ def load_cache(self) -> bool: else: self._mappings = data self._canonical_names = set() + self._mappings.update(STATIC_CORRECTIONS) + self._canonical_names.update(STATIC_CORRECTIONS.values()) logger.info( "Loaded %d card mappings and %d canonical names from cache (%s)", len(self._mappings), diff --git a/tests/test_scryfall.py b/tests/test_scryfall.py index 300e1f0..c975869 100644 --- a/tests/test_scryfall.py +++ b/tests/test_scryfall.py @@ -57,3 +57,38 @@ def test_scryfall_normalizer_warning_on_unrecognized(tmp_path, caplog): result = normalizer.normalize("Fake Card Name 12345") assert result == "Fake Card Name 12345" assert "Fake Card Name 12345" in caplog.text + + +def test_scryfall_normalizer_ratonhnhaketon(tmp_path, caplog): + cache_dir = tmp_path / ".cache" + cache_file = cache_dir / "scryfall_names.json" + cache_dir.mkdir(parents=True) + + payload = { + "mappings": {}, + "canonical": ["Ratonhnhaké\ua789ton", "Circle of Protection: Black"], + } + with open(cache_file, "w", encoding="utf-8") as f: + json.dump(payload, f) + + normalizer = ScryfallNormalizer(cache_dir=str(cache_dir)) + + with caplog.at_level(logging.WARNING): + # Ratonhnhaké:ton with ASCII colon should normalize to modifier letter colon U+A789 + assert normalizer.normalize("Ratonhnhaké:ton") == "Ratonhnhaké\ua789ton" + assert "not recognized" not in caplog.text + + # Unaccented variation + assert normalizer.normalize("Ratonhnhake:ton") == "Ratonhnhaké\ua789ton" + assert "not recognized" not in caplog.text + + # Already canonical form with U+A789 + assert normalizer.normalize("Ratonhnhaké\ua789ton") == "Ratonhnhaké\ua789ton" + assert "not recognized" not in caplog.text + + # Regular colon card should remain unchanged and recognized + assert ( + normalizer.normalize("Circle of Protection: Black") + == "Circle of Protection: Black" + ) + assert "not recognized" not in caplog.text