diff --git a/src/ssvc/namespaces.py b/src/ssvc/namespaces.py index 9eecc653..128ee648 100644 --- a/src/ssvc/namespaces.py +++ b/src/ssvc/namespaces.py @@ -79,13 +79,21 @@ def validate(cls, value: str) -> str: """ valid = NS_PATTERN.match(value) + ext_sep = "/" + frag_sep = "#" + if valid: # pattern matches, so we can proceed with further checks # partition always returns three parts: the part before the separator, the separator itself, and the part after the separator - (base_ns, _, extension) = value.partition("/") + (base_ns, _, extension) = value.partition(ext_sep) # and we don't care about the extension beyond the pattern match above # so base_ns is either the full value or the part before the first slash + # but base_ns might have a fragment + # so we need to split that off if present + if "#" in base_ns: + (base_ns, _, fragment) = base_ns.partition(frag_sep) + if base_ns in cls.__members__.values(): # base_ns is a registered namespaces return value diff --git a/src/test/test_namespaces.py b/src/test/test_namespaces.py index d506fcaf..1469d813 100644 --- a/src/test/test_namespaces.py +++ b/src/test/test_namespaces.py @@ -18,7 +18,6 @@ # DM24-0278 import unittest -import re from ssvc.namespaces import NameSpace from ssvc.utils.patterns import NS_PATTERN @@ -88,6 +87,8 @@ def test_namespace_validator(self): "x_example.test#bar", "x_example.test#baz", "x_example.test#quux", + "ssvc", + "ssvc#test", ]: self.assertEqual(ns, NameSpace.validate(ns)) diff --git a/src/test/test_namespaces_pattern.py b/src/test/test_namespaces_pattern.py index ff7b72d2..f8a9e884 100644 --- a/src/test/test_namespaces_pattern.py +++ b/src/test/test_namespaces_pattern.py @@ -40,6 +40,8 @@ def setUp(self): "cisa", "custom", # not in enum, but valid for the pattern "abc", # not in enum, but valid for the pattern + "ssvc#reference-arch-1", # valid namespace with hash + "x_example.test#test", "x_example.test#test/", "x_example.test#test//.org.example#bar", "ssvc/de-DE/.org.example#reference-arch-1", # valid BCP-47 tag, reverse domain notation, hash