Merge pull request #1178 from utkarshkukreti/issue-1176

fix(uri): fix parse for empty path and '/' or '?' in fragment
This commit is contained in:
Sean McArthur
2017-05-17 10:30:27 -05:00
committed by GitHub

View File

@@ -213,9 +213,8 @@ fn parse_scheme(s: &str) -> Option<usize> {
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) {