From 8c54a884a970beca34ea35c1b27c574124d9c553 Mon Sep 17 00:00:00 2001 From: TowyTowy Date: Wed, 15 Jul 2026 20:22:16 +0200 Subject: [PATCH] fix(scan): resolve "Reg-" prefixed region shortcodes to full names PR #3035 made region/language shortcode lookups case-sensitive by keying REGIONS_BY_SHORTCODE on the uppercase codes, and updated the plain tag lookups to match against the raw (unlowered) tag. The "Reg-" prefix branch was missed: it still lowercased the captured shortcode before looking it up, so it could never hit the now-uppercase-keyed dict. As a result a tag like "[Reg-J]" was stored as the raw "J" instead of resolving to "Japan". Match the shortcode with its original case, like the other lookups, so "[Reg-J]" resolves to "Japan" and "[Reg-U]" to "USA". Non-shortcode values (e.g. "[Reg-PAL]") are still kept verbatim via the fallback. Co-Authored-By: Claude --- backend/handler/filesystem/roms_handler.py | 4 ++-- backend/tests/handler/filesystem/test_roms_handler.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/handler/filesystem/roms_handler.py b/backend/handler/filesystem/roms_handler.py index ae2992e91..14517e45f 100644 --- a/backend/handler/filesystem/roms_handler.py +++ b/backend/handler/filesystem/roms_handler.py @@ -214,8 +214,8 @@ class FSRomsHandler(FSHandler): # Region prefix region_match = REGION_TAG_REGEX.match(raw_tag) if region_match: - key = region_match[1].lower() - regions.append(REGIONS_BY_SHORTCODE.get(key, region_match[1])) + region = region_match[1] + regions.append(REGIONS_BY_SHORTCODE.get(region, region)) continue # Revision prefix diff --git a/backend/tests/handler/filesystem/test_roms_handler.py b/backend/tests/handler/filesystem/test_roms_handler.py index 61af31110..b58bd46b3 100644 --- a/backend/tests/handler/filesystem/test_roms_handler.py +++ b/backend/tests/handler/filesystem/test_roms_handler.py @@ -272,6 +272,15 @@ class TestFSRomsHandler: assert parsed_tags.version == "" assert "versionB" in parsed_tags.other_tags + def test_parse_tags_reg_prefix_resolves_shortcode(self, handler: FSRomsHandler): + """A "Reg-" prefixed shortcode resolves to its full region name.""" + assert "Japan" in handler.parse_tags("Game [Reg-J].rom").regions + assert "USA" in handler.parse_tags("Game [Reg-U].rom").regions + assert "Netherlands" in handler.parse_tags("Game [Reg-NL].rom").regions + + # A value that is not a shortcode is kept verbatim. + assert "PAL" in handler.parse_tags("Game [Reg-PAL].rom").regions + def test_exclude_multi_roms_filters_excluded(self, handler: FSRomsHandler, config): """Test exclude_multi_roms filters out excluded multi-file ROMs""" roms = ["Game1", "excluded_multi", "Game2", "Game3"]