Skip to content

Commit

Permalink
Return error if multiple brackets exist in the authority (hyperium#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeryz authored and Benxiang Ge committed Jul 26, 2021
1 parent f43988c commit 2a30648
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/uri/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl Authority {
.expect("static str is not valid authority")
}


/// Attempt to convert a `Bytes` buffer to a `Authority`.
///
/// This will try to prevent a copy if the type passed is the type used
Expand Down Expand Up @@ -91,13 +90,16 @@ impl Authority {
colon_cnt += 1;
}
b'[' => {
start_bracket = true;
if has_percent {
if has_percent || start_bracket {
// Something other than the userinfo has a `%`, so reject it.
return Err(ErrorKind::InvalidAuthority.into());
}
start_bracket = true;
}
b']' => {
if end_bracket {
return Err(ErrorKind::InvalidAuthority.into());
}
end_bracket = true;

// Those were part of an IPv6 hostname, so forget them...
Expand Down Expand Up @@ -642,4 +644,10 @@ mod tests {
.unwrap_err();
assert_eq!(err.0, ErrorKind::InvalidUriChar);
}

#[test]
fn rejects_invalid_use_of_brackets() {
let err = Authority::parse_non_empty(b"[]@[").unwrap_err();
assert_eq!(err.0, ErrorKind::InvalidAuthority);
}
}

0 comments on commit 2a30648

Please sign in to comment.