Skip to content

Commit 0fd6e52

Browse files
authored
Allow base namespaces to have fragments (e.g., ssvc#example) (#934)
2 parents 286a81b + 65b3bff commit 0fd6e52

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/ssvc/namespaces.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,21 @@ def validate(cls, value: str) -> str:
7979
"""
8080
valid = NS_PATTERN.match(value)
8181

82+
ext_sep = "/"
83+
frag_sep = "#"
84+
8285
if valid:
8386
# pattern matches, so we can proceed with further checks
8487
# partition always returns three parts: the part before the separator, the separator itself, and the part after the separator
85-
(base_ns, _, extension) = value.partition("/")
88+
(base_ns, _, extension) = value.partition(ext_sep)
8689
# and we don't care about the extension beyond the pattern match above
8790
# so base_ns is either the full value or the part before the first slash
8891

92+
# but base_ns might have a fragment
93+
# so we need to split that off if present
94+
if "#" in base_ns:
95+
(base_ns, _, fragment) = base_ns.partition(frag_sep)
96+
8997
if base_ns in cls.__members__.values():
9098
# base_ns is a registered namespaces
9199
return value

src/test/test_namespaces.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# DM24-0278
1919

2020
import unittest
21-
import re
2221

2322
from ssvc.namespaces import NameSpace
2423
from ssvc.utils.patterns import NS_PATTERN
@@ -88,6 +87,8 @@ def test_namespace_validator(self):
8887
"x_example.test#bar",
8988
"x_example.test#baz",
9089
"x_example.test#quux",
90+
"ssvc",
91+
"ssvc#test",
9192
]:
9293
self.assertEqual(ns, NameSpace.validate(ns))
9394

src/test/test_namespaces_pattern.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def setUp(self):
4040
"cisa",
4141
"custom", # not in enum, but valid for the pattern
4242
"abc", # not in enum, but valid for the pattern
43+
"ssvc#reference-arch-1", # valid namespace with hash
44+
"x_example.test#test",
4345
"x_example.test#test/",
4446
"x_example.test#test//.org.example#bar",
4547
"ssvc/de-DE/.org.example#reference-arch-1", # valid BCP-47 tag, reverse domain notation, hash

0 commit comments

Comments
 (0)