Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/ssvc/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/test/test_namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# DM24-0278

import unittest
import re

from ssvc.namespaces import NameSpace
from ssvc.utils.patterns import NS_PATTERN
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 2 additions & 0 deletions src/test/test_namespaces_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down