From 8ba1f19d618ff4632961470622acc2d5a5657b0a Mon Sep 17 00:00:00 2001 From: sinkuu Date: Sat, 25 Feb 2017 20:20:18 +0900 Subject: [PATCH] fix(url): fix panic when questionmark is in fragment --- src/uri.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/uri.rs b/src/uri.rs index ef979773d6..83bfce9493 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -201,7 +201,11 @@ fn parse_query(s: &str) -> Option { 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) {