Fix fragment URI parsing.

This commit is contained in:
ta.tanaka 2018-03-15 19:31:41 +09:00 committed by Sergio Benitez
parent abded5f299
commit 40688a26a6
1 changed files with 5 additions and 1 deletions

View File

@ -36,7 +36,8 @@ impl<'a> URI<'a> {
let end = uri.len();
let (path, query, fragment) = match (qmark, hmark) {
(Some(i), Some(j)) => ((0, i), Some((i+1, j)), Some((j+1, end))),
(Some(i), Some(j)) if i < j => ((0, i), Some((i+1, j)), Some((j+1, end))),
(Some(_i), Some(j)) => ((0, j), None, Some((j+1, end))),
(Some(i), None) => ((0, i), Some((i+1, end)), None),
(None, Some(j)) => ((0, j), None, Some((j+1, end))),
(None, None) => ((0, end), None, None),
@ -544,6 +545,7 @@ mod tests {
test_query("/a/b/c/d/e", None);
test_query("/////", None);
test_query("//a///", None);
test_query("/a/b/c#a?123", None);
}
#[test]
@ -563,6 +565,7 @@ mod tests {
test_fragment("/test#abc", Some("abc"));
test_fragment("/#abc", Some("abc"));
test_fragment("/a/b/c?123#a", Some("a"));
test_fragment("/a/b/c#a?123", Some("a?123"));
test_fragment("/#a", Some("a"));
}
@ -585,5 +588,6 @@ mod tests {
assert_eq!(uri_to_string("//a"), "/a".to_string());
assert_eq!(uri_to_string("/a/b///c"), "/a/b/c".to_string());
assert_eq!(uri_to_string("/a///b/c/d///"), "/a/b/c/d".to_string());
assert_eq!(uri_to_string("/a/b/c#a?123"), "/a/b/c#a?123".to_string());
}
}