Skip to content

Commit

Permalink
Return error if multiple brackets exist in the authority (#445)
Browse files Browse the repository at this point in the history
Closes #435
  • Loading branch information
aeryz authored Dec 8, 2020
1 parent 8be5a58 commit 43c6e84
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 43c6e84

Please sign in to comment.