diff --git a/src/core.rs b/src/core.rs index 52e1b00..c3e2376 100644 --- a/src/core.rs +++ b/src/core.rs @@ -290,6 +290,10 @@ impl Core { loop { match input.peek() { Some('?') | Some('#') | None => break, + Some('%') => self + .parse_pct_enc_char(input) + .map(|_| ()) + .ok_or(Error::InvalidPath)?, Some(ch) if char_path(ch) => {} _ => return Err(Error::InvalidPath), } @@ -316,6 +320,10 @@ impl Core { loop { match input.peek() { Some('#') | None => break, + Some('%') => self + .parse_pct_enc_char(input) + .map(|_| ()) + .ok_or(Error::InvalidPath)?, Some(ch) if char_query(ch) => {} _ => return Err(Error::InvalidQuery), } @@ -342,6 +350,10 @@ impl Core { loop { match input.peek() { None => break, + Some('%') => self + .parse_pct_enc_char(input) + .map(|_| ()) + .ok_or(Error::InvalidPath)?, Some(ch) if char_fragment(ch) => {} _ => return Err(Error::InvalidFragment), } diff --git a/src/did.rs b/src/did.rs index 663d7eb..69a87ad 100644 --- a/src/did.rs +++ b/src/did.rs @@ -279,13 +279,13 @@ mod resolution { #[repr(transparent)] pub struct Path<'a>(Cow<'a, str>); - impl<'a> Default for Path<'a> { + impl Default for Path<'_> { fn default() -> Self { Self::new() } } - impl<'a> Path<'a> { + impl Path<'_> { pub const fn new() -> Self { Self(Cow::Borrowed("")) } diff --git a/tests/parse.rs b/tests/parse.rs index 8fc23e2..a210151 100644 --- a/tests/parse.rs +++ b/tests/parse.rs @@ -116,3 +116,14 @@ fn test_parse_simple_fragment() { assert_eq!(did.query(), None); assert_eq!(did.fragment(), Some("public-key-1")); } + +#[test] +#[rustfmt::skip] +fn test_parse_percent_encoded_components() { + let did: DID = DID::parse("did:example:123456/p%3Ath?qu%3Ary#fr%3Agment").unwrap(); + assert_eq!(did.method(), "example"); + assert_eq!(did.method_id(), "123456"); + assert_eq!(did.path(), "/p%3Ath"); + assert_eq!(did.query(), Some("qu%3Ary")); + assert_eq!(did.fragment(), Some("fr%3Agment")); +}