M12: a backslash ends a web link's host, as web addresses read it

This commit is contained in:
Eric Kaden
2026-10-23 17:28:22 -04:00
parent 3355edad42
commit 352ebb1477
2 changed files with 5 additions and 4 deletions
+4 -3
View File
@@ -779,10 +779,11 @@ fn link_target(href: &str) -> Option<&str> {
ok.then_some(href)
}
/// Whether `after` (a web address past its `//`) names a host: what comes before the path, query
/// or fragment, past any user name and before any port, isn't empty.
/// Whether `after` (a web address past its `//`) names a host: what comes before the path (which a
/// backslash starts too, as web addresses read it), query or fragment, past any user name and
/// before any port, isn't empty.
fn has_host(after: &str) -> bool {
let authority = after.split(['/', '?', '#']).next().unwrap_or_default();
let authority = after.split(['/', '\\', '?', '#']).next().unwrap_or_default();
let host = authority.rsplit('@').next().unwrap_or_default();
// An IPv6 host is bracketed and holds colons of its own.
let host = if host.starts_with('[') { host } else { host.split(':').next().unwrap_or_default() };
+1 -1
View File
@@ -511,7 +511,7 @@ fn a_rule_between_two_pieces_of_a_link_keeps_them_apart() {
fn links_to_anything_but_web_and_email_addresses_stay_plain_text() {
let long = format!("https://example.com/{}", "a".repeat(2100));
let body = format!(
r#"<a href="javascript:app.alert(1)">one</a> <a href="file:///etc/passwd">two</a> <a href="data:text/html,x">three</a> <a href="help.html">four</a> <a href="HTTPS:">five</a> <a href="{long}">six</a> <a href="MailTo:a@example.com">seven</a> <a href="https:///path">eight</a> <a href="https://user@:8080/x">nine</a> <a href="https://user@example.com:8443/x">ten</a>"#
r#"<a href="javascript:app.alert(1)">one</a> <a href="file:///etc/passwd">two</a> <a href="data:text/html,x">three</a> <a href="help.html">four</a> <a href="HTTPS:">five</a> <a href="{long}">six</a> <a href="MailTo:a@example.com">seven</a> <a href="https:///path">eight</a> <a href="https://user@:8080/x">nine</a> <a href="https://\example.com/path">nine and a half</a> <a href="https://user@example.com:8443/x">ten</a>"#
);
let mut doc = Document::open(Arc::new(shell(&rich_draw_form("7in", &body)))).unwrap();
let report = render_into(&mut doc).unwrap();