Merge pull request #1076 from sinkuu/fix_fragment_questionmark

fix(url): fix panic when questionmark is in fragment
This commit is contained in:
Sean McArthur
2017-02-25 09:56:50 -08:00
committed by GitHub

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) {