fix(uri): fix parse for empty path and '/' or '?' in fragment
Fixes #1176.
This commit is contained in:
27
src/uri.rs
27
src/uri.rs
@@ -213,9 +213,8 @@ fn parse_scheme(s: &str) -> Option<usize> {
|
|||||||
|
|
||||||
fn parse_authority(s: &str) -> usize {
|
fn parse_authority(s: &str) -> usize {
|
||||||
let i = s.find("://").map(|p| p + 3).unwrap_or(0);
|
let i = s.find("://").map(|p| p + 3).unwrap_or(0);
|
||||||
s[i..].find('/')
|
s[i..]
|
||||||
.or_else(|| s[i..].find('?'))
|
.find(|ch| ch == '/' || ch == '?' || ch == '#')
|
||||||
.or_else(|| s[i..].find('#'))
|
|
||||||
.map(|end| end + i)
|
.map(|end| end + i)
|
||||||
.unwrap_or(s.len())
|
.unwrap_or(s.len())
|
||||||
}
|
}
|
||||||
@@ -537,6 +536,28 @@ test_parse! {
|
|||||||
port = None,
|
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]
|
#[test]
|
||||||
fn test_uri_parse_error() {
|
fn test_uri_parse_error() {
|
||||||
fn err(s: &str) {
|
fn err(s: &str) {
|
||||||
|
|||||||
Reference in New Issue
Block a user