From 170b711d710a0572fbd396c29be6647a5dcf3836 Mon Sep 17 00:00:00 2001 From: Richard Walters Date: Thu, 15 Oct 2020 12:44:14 -0700 Subject: Version 1.0.1 * Fixed bug in percent encoding of characters \x0 through \xF where they were encoded as "%0" through "%F" rather than "%00" through "%0F". --- Cargo.toml | 2 +- src/codec.rs | 2 +- src/uri.rs | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a3a5af0..34dc7cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rhymuri" -version = "1.0.0" +version = "1.0.1" description = "Implementation of IETF RFC 3986, Uniform Resource Identifier (URI)" authors = ["Richard Walters "] edition = "2018" diff --git a/src/codec.rs b/src/codec.rs index 22d9000..05fcee8 100644 --- a/src/codec.rs +++ b/src/codec.rs @@ -47,7 +47,7 @@ pub fn encode_element( .map(|ci| { match char::try_from(*ci) { Ok(c) if allowed_characters.contains(&c) => c.to_string(), - _ => format!("%{:X}", ci), + _ => format!("%{:02X}", ci), } }) .collect() diff --git a/src/uri.rs b/src/uri.rs index b9e7266..b49cb96 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -1484,6 +1484,18 @@ mod tests { assert_eq!(uri.to_string(), "?foo%2Bbar"); } + #[test] + fn percent_encode_characters_with_two_digits_always() { + for ci in 0_u8..31_u8 { + let mut uri = Uri::default(); + uri.set_query(Some(vec![ci])); + assert_eq!( + uri.to_string(), + format!("?%{:02X}", ci) + ); + } + } + #[test] fn set_illegal_schemes() { let test_vectors = [ -- cgit v1.2.3