mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-03 17:04:43 -06:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d000b2af86 | ||
|
|
da90a56de9 |
+2
-1
File diff suppressed because one or more lines are too long
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user