fix(navigation): classify HTTP schemes case-insensitively

This commit is contained in:
2026-07-09 23:08:15 -04:00
parent 755a6aabd8
commit a6e3aeaf46
8 changed files with 80 additions and 13 deletions
+23
View File
@@ -44,6 +44,14 @@ impl UrlText {
&self.value
}
#[must_use]
pub fn has_any_scheme(&self, schemes: &[&str]) -> bool {
let Some((scheme, _)) = self.value.split_once(':') else {
return false;
};
schemes.iter().any(|candidate| scheme.eq_ignore_ascii_case(candidate))
}
#[must_use]
pub fn display_host(&self) -> String {
Url::parse(&self.value)
@@ -91,3 +99,18 @@ impl fmt::Display for UrlText {
f.write_str(&self.value)
}
}
#[cfg(test)]
mod tests {
use super::UrlText;
#[test]
fn parsed_scheme_matching_preserves_original_text() -> Result<(), Box<dyn std::error::Error>> {
let url = UrlText::parse("HTTPS://Example.com/Path")?;
assert!(url.has_any_scheme(&["http", "https"]));
assert!(!url.has_any_scheme(&["custom"]));
assert_eq!(url.as_str(), "HTTPS://Example.com/Path");
Ok(())
}
}