Skip to content

Commit 460b150

Browse files
Address review feedback on validation and fallback coverage
Signed-off-by: Ali Zulfiqar <codewithfourtix@gmail.com>
1 parent f79b8fe commit 460b150

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/commoncode/urn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ def decode(urn):
125125
"""
126126
segments = [unquote_plus(p) for p in urn.split(":")]
127127

128-
if len(segments) < 3:
129-
raise URNValidationError("Invalid URN: missing namespace or object type.")
130-
131128
if not segments[0] == ("urn"):
132129
raise URNValidationError("Invalid URN prefix. Expected 'urn'.")
133130

131+
if len(segments) < 3:
132+
raise URNValidationError("Invalid URN: missing namespace or object type.")
133+
134134
if not segments[1] == ("dje"):
135135
raise URNValidationError("Invalid URN namespace. Expected 'dje'.")
136136

tests/test_urn.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,9 @@ def test_truncated_urns_raise_validation_error(self):
148148
with self.subTest(value=value):
149149
with self.assertRaises(urn.URNValidationError):
150150
urn.decode(value)
151+
152+
153+
class InvalidPrefixTestCase(unittest.TestCase):
154+
def test_short_non_urn_keeps_prefix_error(self):
155+
with self.assertRaisesRegex(urn.URNValidationError, "Invalid URN prefix"):
156+
urn.decode("x")

0 commit comments

Comments
 (0)