Skip to content

Commit 43c6e84

Browse files
authored
Return error if multiple brackets exist in the authority (#445)
Closes #435
1 parent 8be5a58 commit 43c6e84

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/uri/authority.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ impl Authority {
5050
.expect("static str is not valid authority")
5151
}
5252

53-
5453
/// Attempt to convert a `Bytes` buffer to a `Authority`.
5554
///
5655
/// This will try to prevent a copy if the type passed is the type used
@@ -91,13 +90,16 @@ impl Authority {
9190
colon_cnt += 1;
9291
}
9392
b'[' => {
94-
start_bracket = true;
95-
if has_percent {
93+
if has_percent || start_bracket {
9694
// Something other than the userinfo has a `%`, so reject it.
9795
return Err(ErrorKind::InvalidAuthority.into());
9896
}
97+
start_bracket = true;
9998
}
10099
b']' => {
100+
if end_bracket {
101+
return Err(ErrorKind::InvalidAuthority.into());
102+
}
101103
end_bracket = true;
102104

103105
// Those were part of an IPv6 hostname, so forget them...
@@ -642,4 +644,10 @@ mod tests {
642644
.unwrap_err();
643645
assert_eq!(err.0, ErrorKind::InvalidUriChar);
644646
}
647+
648+
#[test]
649+
fn rejects_invalid_use_of_brackets() {
650+
let err = Authority::parse_non_empty(b"[]@[").unwrap_err();
651+
assert_eq!(err.0, ErrorKind::InvalidAuthority);
652+
}
645653
}

0 commit comments

Comments
 (0)