Skip to content

Commit

Permalink
Fix Uri::host to include brackets of IPv6 literals
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jan 22, 2019
1 parent 4644dae commit e9f0ed9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/uri/authority.rs
Expand Up @@ -497,7 +497,8 @@ fn host(auth: &str) -> &str {
if host_port.as_bytes()[0] == b'[' {
let i = host_port.find(']')
.expect("parsing should validate brackets");
&host_port[1..i]
// ..= ranges aren't available in 1.20, our minimum Rust version...
&host_port[0 .. i + 1]
} else {
host_port.split(':')
.next()
Expand Down
10 changes: 5 additions & 5 deletions src/uri/tests.rs
Expand Up @@ -298,7 +298,7 @@ test_parse! {

scheme_part = part!("http"),
authority_part = part!("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"),
host = Some("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
host = Some("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"),
path = "/",
query = None,
port_part = None,
Expand All @@ -311,7 +311,7 @@ test_parse! {

scheme_part = part!("http"),
authority_part = part!("[::1]"),
host = Some("::1"),
host = Some("[::1]"),
path = "/",
query = None,
port_part = None,
Expand All @@ -324,7 +324,7 @@ test_parse! {

scheme_part = part!("http"),
authority_part = part!("[::]"),
host = Some("::"),
host = Some("[::]"),
path = "/",
query = None,
port_part = None,
Expand All @@ -337,7 +337,7 @@ test_parse! {

scheme_part = part!("http"),
authority_part = part!("[2001:db8::2:1]"),
host = Some("2001:db8::2:1"),
host = Some("[2001:db8::2:1]"),
path = "/",
query = None,
port_part = None,
Expand All @@ -350,7 +350,7 @@ test_parse! {

scheme_part = part!("http"),
authority_part = part!("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8008"),
host = Some("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
host = Some("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"),
path = "/",
query = None,
port_part = Port::from_str("8008").ok(),
Expand Down

0 comments on commit e9f0ed9

Please sign in to comment.