Skip to content

Commit 83173b1

Browse files
Copilotyarikoptic
andcommitted
Build instance name pattern from known_instances
- Changed regex from generic `[-\w._]+` to pattern composed from known instance names - Prevents false matches like `http:000001` or other invalid patterns - Pattern is built dynamically: dandi|dandi-staging|dandi-sandbox|...|ember-sandbox - All existing tests pass, invalid patterns now correctly rejected Co-authored-by: yarikoptic <[email protected]>
1 parent 08ca45f commit 83173b1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

dandi/dandiarchive.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ class _dandi_url_parser:
573573
dandiset_id_grp = f"(?P<dandiset_id>{DANDISET_ID_REGEX})"
574574
# Should absorb port and "api/":
575575
server_grp = "(?P<server>(?P<protocol>https?)://(?P<hostname>[^/]+)/(api/)?)"
576+
# Build instance name pattern from known instances to avoid matching unknown patterns
577+
instance_name_pattern = "|".join(re.escape(name) for name in known_instances.keys())
576578
known_urls: list[tuple[re.Pattern[str], dict[str, Any], str]] = [
577579
# List of (regex, settings, display string) triples
578580
#
@@ -589,7 +591,7 @@ class _dandi_url_parser:
589591
# for not only "dandiarchive.org" URLs
590592
(
591593
re.compile(
592-
rf"(?P<instance_name>[-\w._]+):"
594+
rf"(?P<instance_name>{instance_name_pattern}):"
593595
rf"{dandiset_id_grp}"
594596
rf"(/(?P<version>{VERSION_REGEX}))?",
595597
flags=re.I,

0 commit comments

Comments
 (0)