From ffe715c7f4906c43a201de91ab474f068de064a0 Mon Sep 17 00:00:00 2001 From: G26Karthik Date: Sat, 31 Oct 2026 22:12:58 +0530 Subject: [PATCH] fix(uri): reject trailing path, query or fragment in Authority::from_static --- src/uri/authority.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/uri/authority.rs b/src/uri/authority.rs index c5479cb24..c2a94c2e7 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();