diff options
| author | bbb651 🇮🇱 <53972231+bbb651@users.noreply.github.com> | 2025-01-06 17:13:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-06 15:13:17 +0000 |
| commit | ce7f680fd5f21f79548280c844e1abbabc0d4e46 (patch) | |
| tree | 4dc0a2c0d0aec24c2c4798206b8ede371b007b82 /crates/typst-library | |
| parent | cb8d862a55601127a1e3ff02feaefdabd37b583f (diff) | |
Avoid stripping url prefixes multiple times or multiple prefixes (#5659)
Diffstat (limited to 'crates/typst-library')
| -rw-r--r-- | crates/typst-library/src/model/link.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/crates/typst-library/src/model/link.rs b/crates/typst-library/src/model/link.rs index 8ab129fd..bbc47da0 100644 --- a/crates/typst-library/src/model/link.rs +++ b/crates/typst-library/src/model/link.rs @@ -135,10 +135,10 @@ impl Show for Packed<LinkElem> { } fn body_from_url(url: &Url) -> Content { - let mut text = url.as_str(); - for prefix in ["mailto:", "tel:"] { - text = text.trim_start_matches(prefix); - } + let text = ["mailto:", "tel:"] + .into_iter() + .find_map(|prefix| url.strip_prefix(prefix)) + .unwrap_or(url); let shorter = text.len() < url.len(); TextElem::packed(if shorter { text.into() } else { (**url).clone() }) } |
