From 14633c64d891ff00d9b81f4d19f73107ae0daa10 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Sat, 28 Dec 2024 12:20:47 +0100 Subject: [PATCH] Allow non-percent-encoded spaces in path The space character is not a reserved character. While it MAY be used in percent-encoded form, this is not mandatory and it is acceptable to use raw spaces in URL paths. Add Space (0x20) to the list of characters that don't need to be percent-encoded. --- src/uri/path.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/uri/path.rs b/src/uri/path.rs index df00c415..170e1681 100644 --- a/src/uri/path.rs +++ b/src/uri/path.rs @@ -44,7 +44,7 @@ impl PathAndQuery { // percent-encoded in the path. If it should have been // percent-encoded, then error. #[rustfmt::skip] - 0x21 | + 0x20..=0x21 | 0x24..=0x3B | 0x3D | 0x40..=0x5F | @@ -561,6 +561,11 @@ mod tests { assert_eq!("/🍕", pq("/🍕").path()); } + #[test] + fn allow_space_in_path() { + assert_eq!("/dav/With Space/", pq("/dav/With Space/").path()); + } + #[test] fn allow_utf8_in_query() { assert_eq!(Some("pizza=🍕"), pq("/test?pizza=🍕").query());