From 70a3f76a276a429980a8fc877cf4de175364d708 Mon Sep 17 00:00:00 2001 From: Laurent Arnoud Date: Sun, 5 Feb 2017 12:54:46 +0100 Subject: [PATCH] test(uri): fix URI parse error tests Add also test parse authority without port --- src/uri.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/uri.rs b/src/uri.rs index daa1c394..bebfe630 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -86,6 +86,8 @@ impl Uri { query: parse_query(s), fragment: parse_fragment(s), }) + } else if (s.contains("/") || s.contains("?")) && !s.contains("://") { + return Err(Error::Method) } else { Ok(Uri { source: s.to_owned().into(), @@ -315,6 +317,18 @@ test_parse! { fragment = None, } +test_parse! { + test_uri_parse_authority_no_port, + "localhost", + + scheme = None, + authority = Some("localhost"), + path = "", + query = None, + fragment = None, + port = None, +} + test_parse! { test_uri_parse_authority_form, "localhost:3000", @@ -358,10 +372,11 @@ fn test_uri_parse_error() { } err("http://"); - //TODO: these should error - //err("htt:p//host"); - //err("hyper.rs/"); - //err("hyper.rs?key=val"); + err("htt:p//host"); + err("hyper.rs/"); + err("hyper.rs?key=val"); + err("localhost/"); + err("localhost?key=val"); } #[test]