From e8e8593c77d531dfc0e3d32f52d8fe37c01789ed Mon Sep 17 00:00:00 2001 From: Andrew Baxter <> Date: Fri, 10 May 2024 22:53:12 +0900 Subject: [PATCH] Allow empty authority in absolute URIs --- src/uri/mod.rs | 5 ----- src/uri/tests.rs | 14 +++++++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/uri/mod.rs b/src/uri/mod.rs index 767f0743..c573c99e 100644 --- a/src/uri/mod.rs +++ b/src/uri/mod.rs @@ -862,11 +862,6 @@ fn parse_full(mut s: Bytes) -> Result { }); } - // Authority is required when absolute - if authority_end == 0 { - return Err(ErrorKind::InvalidFormat.into()); - } - let authority = s.split_to(authority_end); let authority = Authority { data: unsafe { ByteStr::from_utf8_unchecked(authority) }, diff --git a/src/uri/tests.rs b/src/uri/tests.rs index 719cb94e..2de3897e 100644 --- a/src/uri/tests.rs +++ b/src/uri/tests.rs @@ -384,6 +384,19 @@ test_parse! { port = Port::from_str("8008").ok(), } +test_parse! { + test_file_no_host, + "file:///some/path", + [], + + scheme = part!("file"), + authority = None, + host = None, + path = "/some/path", + query = None, + port = None, +} + test_parse! { test_percentage_encoded_path, "/echo/abcdefgh_i-j%20/abcdefg_i-j%20478", @@ -419,7 +432,6 @@ fn test_uri_parse_error() { Uri::from_str(s).unwrap_err(); } - err("http://"); err("htt:p//host"); err("hyper.rs/"); err("hyper.rs?key=val");