diff --git a/src/uri.rs b/src/uri.rs index d56ad74f..7e13f587 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -213,9 +213,8 @@ fn parse_scheme(s: &str) -> Option { fn parse_authority(s: &str) -> usize { let i = s.find("://").map(|p| p + 3).unwrap_or(0); - s[i..].find('/') - .or_else(|| s[i..].find('?')) - .or_else(|| s[i..].find('#')) + s[i..] + .find(|ch| ch == '/' || ch == '?' || ch == '#') .map(|end| end + i) .unwrap_or(s.len()) } @@ -537,6 +536,28 @@ test_parse! { port = None, } +test_parse! { + test_uri_parse_absolute_form_with_empty_path_and_fragment_with_slash, + "http://127.0.0.1#foo/bar", + scheme = Some("http"), + authority = Some("127.0.0.1"), + path = "/", + query = None, + fragment = Some("foo/bar"), + port = None, +} + +test_parse! { + test_uri_parse_absolute_form_with_empty_path_and_fragment_with_questionmark, + "http://127.0.0.1#foo?bar", + scheme = Some("http"), + authority = Some("127.0.0.1"), + path = "/", + query = None, + fragment = Some("foo?bar"), + port = None, +} + #[test] fn test_uri_parse_error() { fn err(s: &str) {