aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/codec.rs2
-rw-r--r--src/uri.rs12
2 files changed, 13 insertions, 1 deletions
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
@@ -1485,6 +1485,18 @@ mod tests {
}
#[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 = [
"ab_de",