summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2025-02-11 12:13:40 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2025-02-11 12:14:31 +1300
commit4ce5f34163756f39fefa5114c87922999e9d6320 (patch)
tree6cd99a9d2c116e2db609996dfac57adb5e38a056 /src/main.rs
parent34156a8738eb99d71f69a7334ab2eced52dc7af7 (diff)
downloadtoaster-4ce5f34163756f39fefa5114c87922999e9d6320.zip
URL-encode special characters in unsanitized paths
Unlike for internal links, external links are never sanitized. When an external link contained an apostrophe or a double-quote character, it would prematurely terminate the href property of the containing <a> tag and break the link. Paths in internal and external links are now passed through a new url_encode function, which replaces quote characters with the percent-encoded equivalent.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index dc432ad..1ea25d2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -167,4 +167,14 @@ pub fn make_url_safe(text: &str) -> String {
.collect()
}
-
+pub fn url_encode(text: &str) -> String {
+ let mut output = String::new();
+ for c in text.chars() {
+ match c {
+ '"' => output.push_str("%22"),
+ '\'' => output.push_str("%27"),
+ _ => output.push(c),
+ }
+ }
+ return output;
+}