Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}