PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M12: a backslash ends a web link's host, as web addresses read it
Eric Kaden352ebb1477d6
diff --git a/crates/xfa/src/pdf.rs b/crates/xfa/src/pdf.rsindex 833fae875..61b287e3d 100644--- a/crates/xfa/src/pdf.rs+++ b/crates/xfa/src/pdf.rs@@ -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() };diff --git a/crates/xfa/src/tests.rs b/crates/xfa/src/tests.rsindex e4a0c410d..9901903bc 100644--- a/crates/xfa/src/tests.rs+++ b/crates/xfa/src/tests.rs@@ -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:[email protected]">seven</a> <a href="https:///path">eight</a> <a href="https://user@:8080/x">nine</a> <a href="https://[email protected]: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:[email protected]">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://[email protected]: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();