Skip to content

Commit 12d01e4

Browse files
authored
Merge pull request #1178 from utkarshkukreti/issue-1176
fix(uri): fix parse for empty path and '/' or '?' in fragment
2 parents 33eb8f9 + 559f21a commit 12d01e4

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/uri.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ fn parse_scheme(s: &str) -> Option<usize> {
213213

214214
fn parse_authority(s: &str) -> usize {
215215
let i = s.find("://").map(|p| p + 3).unwrap_or(0);
216-
s[i..].find('/')
217-
.or_else(|| s[i..].find('?'))
218-
.or_else(|| s[i..].find('#'))
216+
s[i..]
217+
.find(|ch| ch == '/' || ch == '?' || ch == '#')
219218
.map(|end| end + i)
220219
.unwrap_or(s.len())
221220
}
@@ -537,6 +536,28 @@ test_parse! {
537536
port = None,
538537
}
539538

539+
test_parse! {
540+
test_uri_parse_absolute_form_with_empty_path_and_fragment_with_slash,
541+
"http://127.0.0.1#foo/bar",
542+
scheme = Some("http"),
543+
authority = Some("127.0.0.1"),
544+
path = "/",
545+
query = None,
546+
fragment = Some("foo/bar"),
547+
port = None,
548+
}
549+
550+
test_parse! {
551+
test_uri_parse_absolute_form_with_empty_path_and_fragment_with_questionmark,
552+
"http://127.0.0.1#foo?bar",
553+
scheme = Some("http"),
554+
authority = Some("127.0.0.1"),
555+
path = "/",
556+
query = None,
557+
fragment = Some("foo?bar"),
558+
port = None,
559+
}
560+
540561
#[test]
541562
fn test_uri_parse_error() {
542563
fn err(s: &str) {

0 commit comments

Comments
 (0)