Merge pull request #3658 from rommapp/copilot/bug-fix-non-version-filename-tags

Refine filename version-tag parsing to avoid swallowing generic `v*` tags
This commit is contained in:
Georges-Antoine Assi
2026-07-03 08:44:18 -04:00
committed by GitHub
2 changed files with 33 additions and 2 deletions

View File

@@ -141,7 +141,7 @@ def _make_file_hash(
GENERIC_TAG_REGEX = re.compile(r"\(([^)]+)\)|\[([^]]+)\]")
VERSION_TAG_REGEX = re.compile(r"^(?:version|ver|v)[\s_-]?(.*)", re.I)
VERSION_TAG_REGEX = re.compile(r"^(?:version|ver|v)(?:[\s_-](.*)|([.\d].*))", re.I)
REGION_TAG_REGEX = re.compile(r"^reg[\s|-](.*)$", re.I)
REVISION_TAG_REGEX = re.compile(r"^rev[\s|-](.*)$", re.I)
@@ -208,7 +208,7 @@ class FSRomsHandler(FSHandler):
# Version
version_match = VERSION_TAG_REGEX.match(raw_tag)
if version_match:
version = version_match[1]
version = (version_match[1] or version_match[2] or "").strip()
continue
# Region prefix

View File

@@ -223,6 +223,37 @@ class TestFSRomsHandler:
parsed_tags = handler.parse_tags(fs_name)
assert parsed_tags.version == "1.2.3"
fs_name = "My Game (version B).rom"
parsed_tags = handler.parse_tags(fs_name)
assert parsed_tags.version == "B"
fs_name = "My Game (v1.2a).rom"
parsed_tags = handler.parse_tags(fs_name)
assert parsed_tags.version == "1.2a"
# A separator with no version after it must yield "" (str), never None.
fs_name = "My Game (v-).rom"
parsed_tags = handler.parse_tags(fs_name)
assert parsed_tags.version == ""
# A trailing separator leaves leading whitespace the group must strip.
fs_name = "My Game (v 1.2.3).rom"
parsed_tags = handler.parse_tags(fs_name)
assert parsed_tags.version == "1.2.3"
def test_parse_tags_non_version_tags_starting_with_v(self, handler: FSRomsHandler):
"""Test parse_tags keeps non-version tags starting with v as generic tags"""
fs_name = "Rom [2026] [Variation].rom"
parsed_tags = handler.parse_tags(fs_name)
assert parsed_tags.version == ""
assert "2026" in parsed_tags.other_tags
assert "Variation" in parsed_tags.other_tags
fs_name = "Rom [versionB].rom"
parsed_tags = handler.parse_tags(fs_name)
assert parsed_tags.version == ""
assert "versionB" in parsed_tags.other_tags
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"]