Fix fragment URI parsing.

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

View File

@ -32,7 +32,8 @@ impl<'a> Uri<'a> {
let end = uri.len(); let end = uri.len();
let (path, query, fragment) = match (qmark, hmark) { 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), (Some(i), None) => ((0, i), Some((i+1, end)), None),
(None, Some(j)) => ((0, j), None, Some((j+1, end))), (None, Some(j)) => ((0, j), None, Some((j+1, end))),
(None, None) => ((0, end), None, None), (None, None) => ((0, end), None, None),
@ -547,6 +548,7 @@ mod tests {
test_query("/a/b/c/d/e", None); test_query("/a/b/c/d/e", None);
test_query("/////", None); test_query("/////", None);
test_query("//a///", None); test_query("//a///", None);
test_query("/a/b/c#a?123", None);
} }
#[test] #[test]
@ -566,6 +568,7 @@ mod tests {
test_fragment("/test#abc", Some("abc")); test_fragment("/test#abc", Some("abc"));
test_fragment("/#abc", Some("abc")); test_fragment("/#abc", Some("abc"));
test_fragment("/a/b/c?123#a", Some("a")); test_fragment("/a/b/c?123#a", Some("a"));
test_fragment("/a/b/c#a?123", Some("a?123"));
test_fragment("/#a", Some("a")); test_fragment("/#a", Some("a"));
} }
@ -588,5 +591,6 @@ mod tests {
assert_eq!(uri_to_string("//a"), "/a".to_string()); 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"), "/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/d///"), "/a/b/c/d".to_string());
assert_eq!(uri_to_string("/a/b/c#a?123"), "/a/b/c#a?123".to_string());
} }
} }