Skip to content

test(dids): add DID syntax edge cases and accessor coverage - #710

Open
gbdevw wants to merge 2 commits into
spruceid:mainfrom
gbdevw:test/did-validation-edge-cases
Open

gbdevw wants to merge 2 commits into
spruceid:mainfrom
gbdevw:test/did-validation-edge-cases

Conversation

@gbdevw

@gbdevw gbdevw commented Sep 16, 2026

Copy link
Copy Markdown

Summary

Adds unit tests for generic DID syntax parsing and for the public DID / DIDBuf accessors in crates/dids/core/src/did.rs. No production code changes.

Why

DID::new was only covered by 4 accept vectors and 3 reject vectors. A few ABNF cases that are easy to get wrong were untested, in particular consecutive colons in method-specific-id and malformed percent-encoding. The public accessors (method_name, method_specific_id, as_str, …) were also unexercised.

What

Accept:

  • digits in the method name (did:m1:1)
  • -, _ in the method-specific id
  • lowercase percent-encoding (%af)
  • consecutive colons (did:m::si:::1), allowed by
    method-specific-id = *( *idchar ":" ) 1*idchar

Reject:

  • invalid scheme / method charset
  • empty input, empty method, trailing colon
  • incomplete or invalid pct-encoding (%, %0, %0G)
  • DID URLs (/, ?, #) which are not DIDs

Accessors:

  • as_str / as_bytes / method_name / method_specific_id (and *_bytes)
  • Display and Deref on DID
  • DIDBuf::from_string, as_did, to_owned round-trip
  • consecutive colons are kept inside method_specific_id (":si:::1")

Notes

  • Lowercase hex in pct-encoding is accepted on purpose: HEXDIG quoted strings are case-insensitive in RFC 5234, and RFC 3986 §2.1 treats %af and %AF as equivalent.
  • Existing vectors (did:jwk:…, did:web:example.com%3A443:…) already cover . and uppercase ALPHA in the method-specific id.

@CLAassistant

CLAassistant commented Sep 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants