Avoid stripping url prefixes multiple times or multiple prefixes (#5659)

This commit is contained in:
bbb651 🇮🇱 2025-01-06 17:13:17 +02:00 committed by GitHub
parent cb8d862a55
commit ce7f680fd5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -135,10 +135,10 @@ impl Show for Packed<LinkElem> {
} }
fn body_from_url(url: &Url) -> Content { fn body_from_url(url: &Url) -> Content {
let mut text = url.as_str(); let text = ["mailto:", "tel:"]
for prefix in ["mailto:", "tel:"] { .into_iter()
text = text.trim_start_matches(prefix); .find_map(|prefix| url.strip_prefix(prefix))
} .unwrap_or(url);
let shorter = text.len() < url.len(); let shorter = text.len() < url.len();
TextElem::packed(if shorter { text.into() } else { (**url).clone() }) TextElem::packed(if shorter { text.into() } else { (**url).clone() })
} }