Skip to content

Commit 8c54a88

Browse files
TowyTowyclaude
andcommitted
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 <noreply@anthropic.com>
1 parent b85ecc5 commit 8c54a88

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

backend/handler/filesystem/roms_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ def parse_tags(self, fs_name: str) -> ParsedTags:
214214
# Region prefix
215215
region_match = REGION_TAG_REGEX.match(raw_tag)
216216
if region_match:
217-
key = region_match[1].lower()
218-
regions.append(REGIONS_BY_SHORTCODE.get(key, region_match[1]))
217+
region = region_match[1]
218+
regions.append(REGIONS_BY_SHORTCODE.get(region, region))
219219
continue
220220

221221
# Revision prefix

backend/tests/handler/filesystem/test_roms_handler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ def test_parse_tags_non_version_tags_starting_with_v(self, handler: FSRomsHandle
272272
assert parsed_tags.version == ""
273273
assert "versionB" in parsed_tags.other_tags
274274

275+
def test_parse_tags_reg_prefix_resolves_shortcode(self, handler: FSRomsHandler):
276+
"""A "Reg-" prefixed shortcode resolves to its full region name."""
277+
assert "Japan" in handler.parse_tags("Game [Reg-J].rom").regions
278+
assert "USA" in handler.parse_tags("Game [Reg-U].rom").regions
279+
assert "Netherlands" in handler.parse_tags("Game [Reg-NL].rom").regions
280+
281+
# A value that is not a shortcode is kept verbatim.
282+
assert "PAL" in handler.parse_tags("Game [Reg-PAL].rom").regions
283+
275284
def test_exclude_multi_roms_filters_excluded(self, handler: FSRomsHandler, config):
276285
"""Test exclude_multi_roms filters out excluded multi-file ROMs"""
277286
roms = ["Game1", "excluded_multi", "Game2", "Game3"]

0 commit comments

Comments
 (0)