Skip to content

Commit

Permalink
Merge pull request #1076 from sinkuu/fix_fragment_questionmark
Browse files Browse the repository at this point in the history
fix(url): fix panic when questionmark is in fragment
  • Loading branch information
seanmonstar committed Feb 25, 2017
2 parents 6eb0753 + 8ba1f19 commit 359f5ff
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 359f5ff

Please sign in to comment.