fix(url): fix panic when questionmark is in fragment

This commit is contained in:
sinkuu
2017-02-25 20:20:18 +09:00
parent 6eb0753921
commit 8ba1f19d61

View File

@@ -201,7 +201,11 @@ fn parse_query(s: &str) -> Option<usize> {
Some(i) => {
let frag_pos = s.find('#').unwrap_or(s.len());
return Some(frag_pos - i - 1);
if frag_pos < i + 1 {
None
} else {
Some(frag_pos - i - 1)
}
},
None => None,
}
@@ -413,6 +417,18 @@ test_parse! {
port = Some(443),
}
test_parse! {
test_uri_parse_fragment_questionmark,
"http://127.0.0.1/#?",
scheme = Some("http"),
authority = Some("127.0.0.1"),
path = "/",
query = None,
fragment = Some("?"),
port = None,
}
#[test]
fn test_uri_parse_error() {
fn err(s: &str) {