Skip to content

Commit 7d46b40

Browse files
committed
rf: make "INSTANCE-NAME:ID" URI pattern more stringent - no arbitrary case, only capital
So it would avoid confusion with dandi:// URL. Also fixing up tests for prior commit renames
1 parent 01e4e48 commit 7d46b40

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

dandi/dandiarchive.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,9 @@ class _dandi_url_parser:
574574
# Should absorb port and "api/":
575575
server_grp = "(?P<server>(?P<protocol>https?)://(?P<hostname>[^/]+)/(api/)?)"
576576
# 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())
577+
instance_name_pattern = "|".join(
578+
re.escape(name.upper()) for name in known_instances
579+
)
578580
known_urls: list[tuple[re.Pattern[str], dict[str, Any], str]] = [
579581
# List of (regex, settings, display string) triples
580582
#
@@ -594,7 +596,6 @@ class _dandi_url_parser:
594596
rf"(?P<instance_name>{instance_name_pattern}):"
595597
rf"{dandiset_id_grp}"
596598
rf"(/(?P<version>{VERSION_REGEX}))?",
597-
flags=re.I,
598599
),
599600
{},
600601
"<INSTANCE>:<dandiset id>[/<version>]",

dandi/tests/test_dandiapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def test_asset_as_readable_open(new_dandiset: SampleDandiset, tmp_path: Path) ->
869869
("dandi", "DANDI_API_KEY"),
870870
("dandi-api-local-docker-tests", "DANDI_API_LOCAL_DOCKER_TESTS_API_KEY"),
871871
("dandi-sandbox", "DANDI_SANDBOX_API_KEY"),
872-
("ember-sandbox", "EMBER_SANDBOX_API_KEY"),
872+
("ember-dandi-sandbox", "EMBER_SANDBOX_API_KEY"),
873873
],
874874
)
875875
def test_get_api_key_env_var(instance_name: str, expected_env_var_name: str) -> None:

dandi/tests/test_dandiarchive.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@
108108
version_id="draft",
109109
),
110110
),
111-
# lower cased
111+
# numeric version
112112
(
113-
"dandi:000027/0.210831.2033",
113+
"DANDI:000027/0.210831.2033",
114114
DandisetURL(
115115
instance=known_instances["dandi"],
116116
dandiset_id="000027",
@@ -126,14 +126,6 @@
126126
version_id=None,
127127
),
128128
),
129-
(
130-
"dandi-sandbox:000029/draft",
131-
DandisetURL(
132-
instance=known_instances["dandi-sandbox"],
133-
dandiset_id="000029",
134-
version_id="draft",
135-
),
136-
),
137129
(
138130
"LINC:000029",
139131
DandisetURL(
@@ -143,25 +135,25 @@
143135
),
144136
),
145137
(
146-
"linc:000029/0.210831.2033",
138+
"LINC:000029/0.210831.2033",
147139
DandisetURL(
148140
instance=known_instances["linc"],
149141
dandiset_id="000029",
150142
version_id="0.210831.2033",
151143
),
152144
),
153145
(
154-
"EMBER:000029",
146+
"EMBER-DANDI:000029",
155147
DandisetURL(
156-
instance=known_instances["ember"],
148+
instance=known_instances["ember-dandi"],
157149
dandiset_id="000029",
158150
version_id=None,
159151
),
160152
),
161153
(
162-
"ember-sandbox:000029/draft",
154+
"EMBER-DANDI-SANDBOX:000029/draft",
163155
DandisetURL(
164-
instance=known_instances["ember-sandbox"],
156+
instance=known_instances["ember-dandi-sandbox"],
165157
dandiset_id="000029",
166158
version_id="draft",
167159
),

0 commit comments

Comments
 (0)