Skip to content

Commit 186e9e3

Browse files
committed
refactor: match the OSW-ID as the 32 hex characters it is
- drop the dashed-uuid alternation, an OSW-ID never carries dashes - use [0-9a-fA-F]{32} as regex_pattern.py already does - drop IGNORECASE, the prefix was never case insensitive before
1 parent 79a645b commit 186e9e3

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎src/osw/utils/wiki.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
OSW_ID_PATTERN = re.compile(
99
r"^(?:OSW)?" # the prefix, absent when a bare uuid is passed
10-
r"([0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})"
11-
r"(?:\.[\w-]+)*$", # file suffixes, e.g. '.png' or '.drawio.png'
12-
re.IGNORECASE,
10+
r"([0-9a-fA-F]{32})" # the uuid, in the hex form an OSW-ID carries it
11+
r"(?:\.[\w-]+)*$" # file suffixes, e.g. '.png' or '.drawio.png'
1312
)
1413
"""Matches an OSW-ID with an optional prefix and any number of file suffixes"""
1514

‎tests/utils/utils_test.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ def test_get_uuid_ignores_file_suffixes(suffix):
4242
assert get_uuid(osw_id) == uuid_
4343

4444

45-
@pytest.mark.parametrize("prefix", ["", "OSW", "osw"])
46-
def test_get_uuid_accepts_a_bare_uuid(prefix):
45+
def test_get_uuid_accepts_a_bare_uuid():
46+
"""The prefix is optional, as it was when it was stripped by str.replace."""
4747
uuid_ = uuid.uuid4()
4848

49-
assert get_uuid(f"{prefix}{str(uuid_).replace('-', '')}") == uuid_
50-
assert get_uuid(f"{prefix}{uuid_}") == uuid_ # dashed
49+
assert get_uuid(str(uuid_).replace("-", "")) == uuid_
5150

5251

5352
@pytest.mark.parametrize(
@@ -60,6 +59,8 @@ def test_get_uuid_accepts_a_bare_uuid(prefix):
6059
"OSW2ea5b605c91f4e5a95593dff79fdd4a5x",
6160
"OSW2ea5b605c91f4e5a95593dff79fdd4a5.", # empty suffix
6261
"OSWzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
62+
"osw2ea5b605c91f4e5a95593dff79fdd4a5", # prefix is case sensitive
63+
"2ea5b605-c91f-4e5a-9559-3dff79fdd4a5", # an OSW-ID carries no dashes
6364
],
6465
)
6566
def test_get_uuid_rejects_what_is_not_an_osw_id(osw_id):

0 commit comments

Comments
 (0)