fix(url): fix panic when questionmark is in fragment
This commit is contained in:
18
src/uri.rs
18
src/uri.rs
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user