Skip to content

Raise URNValidationError for truncated URNs - #109

Open
codewithfourtix wants to merge 2 commits into
aboutcode-org:mainfrom
codewithfourtix:fix-short-urn-validation
Open

codewithfourtix wants to merge 2 commits into
aboutcode-org:mainfrom
codewithfourtix:fix-short-urn-validation

Conversation

@codewithfourtix

Copy link
Copy Markdown

decode("urn") and decode("urn:dje") raise IndexError while reading missing segments. Check the segment count first so malformed input raises the documented URNValidationError.

Adds regression cases for empty and truncated URNs.

Signed-off-by: Ali Zulfiqar <codewithfourtix@gmail.com>
Copilot AI lite review requested due to automatic review settings September 5, 2026 17:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is small, targeted, and includes regression tests validating the intended exception behavior for malformed URNs.

Pull request overview

This PR fixes urn.decode() so that empty/truncated URNs no longer raise IndexError, and instead consistently raise the documented URNValidationError, with regression coverage added for these malformed inputs.

Changes:

  • Add an upfront segment-count validation in urn.decode() to prevent IndexError on truncated URNs.
  • Add regression tests covering empty and truncated URN strings.
File summaries
File Description
src/commoncode/urn.py Adds a segment-length guard in decode() to raise URNValidationError for truncated inputs.
tests/test_urn.py Adds regression tests asserting URNValidationError for empty/truncated URNs.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/commoncode/urn.py Resolved
Signed-off-by: Ali Zulfiqar <codewithfourtix@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants