Skip to content
Closed
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
12 changes: 10 additions & 2 deletions src/uri/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ impl Authority {
#[inline]
pub const fn from_static(src: &'static str) -> Self {
match validate_authority_bytes(src.as_bytes()) {
Ok(_) => Authority {
Ok(end) if end == src.len() => Authority {
data: ByteStr::from_static(src),
},
Err(_) => panic!("static str is not valid authority"),
_ => panic!("static str is not valid authority"),
}
}

Expand Down Expand Up @@ -610,6 +610,14 @@ mod tests {
assert_eq!(authority, "example.com");
}

#[test]
#[should_panic(expected = "static str is not valid authority")]
fn from_static_rejects_trailing_path() {
// `parse` rejects this, `from_static` must too.
assert!("https://127.0.0.1".parse::<Authority>().is_err());
Authority::from_static("https://127.0.0.1");
}

#[test]
fn not_equal_with_a_str_of_a_different_authority() {
let authority: Authority = "example.com".parse().unwrap();
Expand Down