diff --git a/src/uri/authority.rs b/src/uri/authority.rs index c5479cb2..c2a94c2e 100644 --- a/src/uri/authority.rs +++ b/src/uri/authority.rs @@ -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"), } } @@ -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::().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();