Compare commits

...
5 changed files with 32 additions and 4 deletions
+2 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,5 +1,5 @@
use super::balloons::over_balloon;
use super::links::{field_showing_code, is_followable_link, is_generated_bookmark_link, link_under};
use super::links::{field_showing_code, for_launcher, is_followable_link, is_generated_bookmark_link, link_under};
use super::navigation::page_at;
use super::story::{enters_header_footer, in_text_box, part_kind, text_box_host};
use super::{CanvasState, DocLayout, PartKind, Pos, Pos2, Rect, StoryRef, Ui, WordApp, json};
@@ -335,7 +335,7 @@ fn handle_primary_press(
let _ = app.run("select.collapse", json!({}));
}
} else if is_followable_link(&link) {
app.canvas.open_url = Some(link);
app.canvas.open_url = Some(for_launcher(&link));
} else {
app.status(tl!("Only web (http, https) and email (mailto) links can be followed"));
}
+16
View File
@@ -48,3 +48,19 @@ pub(super) fn is_generated_bookmark_link(link: &str) -> bool {
pub(super) fn is_followable_link(url: &str) -> bool {
wordcraft_doc::link::is_web_or_mail_link(url)
}
/// `url` as it is handed to the system to open: the characters a Windows command line acts on
/// (`|`, `<`, `>`, `(`, `)`, `^`, `!`, `"`, and spaces) percent-encoded, which a browser reads the
/// same. Under WSL the browser crate starts the link through `cmd.exe /c start`, escaping only
/// `^` and `&`, so `https://x/a|calc` would run `calc`. `&` is left alone: it separates a query's
/// fields, and that launcher escapes it.
pub(super) fn for_launcher(url: &str) -> String {
let mut out = String::with_capacity(url.len());
for c in url.chars() {
match c {
'|' | '<' | '>' | '(' | ')' | '^' | '!' | '"' | ' ' => out.push_str(&format!("%{:02X}", c as u32)),
c => out.push(c),
}
}
out
}
+11
View File
@@ -2646,6 +2646,17 @@ fn only_web_and_email_links_are_followed() {
}
}
#[test]
fn followed_links_reach_the_launcher_without_command_line_syntax() {
use super::links::for_launcher;
assert_eq!(for_launcher("https://x.example/a|calc"), "https://x.example/a%7Ccalc");
assert_eq!(for_launcher("https://x.example/a^b<c>d(e)f!g\"h i"), "https://x.example/a%5Eb%3Cc%3Ed%28e%29f%21g%22h%20i");
// Ordinary links, queries and existing escapes are unchanged.
for ok in ["https://example.com/a?b=1&c=2#d", "mailto:someone@example.com", "https://example.com/caf%C3%A9"] {
assert_eq!(for_launcher(ok), ok);
}
}
/// Ctrl+click on a link to a bookmark puts the caret at the bookmark's start, as Word does;
/// only Go To selects the bookmark's text (#1236).
#[test]
+1 -1
View File
File diff suppressed because one or more lines are too long