summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-05-21 13:09:11 +1200
committerBen Bridle <ben@derelict.engineering>2025-05-21 19:50:09 +1200
commit29ffca829925a30ff920c79f94ec1b3dbf48f8fa (patch)
treea1be9855cab01f68e61066daccc6be7ae22a948b
parentd98b9a0e6b8cbe499e92a49cd749d0248f0d8e47 (diff)
downloadtoaster-29ffca829925a30ff920c79f94ec1b3dbf48f8fa.zip
Sanitize quotes in file paths
-rw-r--r--src/generate_html.rs27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs
index e329739..0de42a5 100644
--- a/src/generate_html.rs
+++ b/src/generate_html.rs
@@ -176,6 +176,7 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs
}
}
let label = sanitize_text(label, true);
+ let path = sanitize_text(&path, false);
match extension.to_lowercase().as_str() {
"jpg"|"jpeg"|"png"|"webp"|"gif"|"tiff" => html!(
"<figure><a href='{path}'><img src='{path}' alt='{label}' title='{label}' /></a></figure>"),
@@ -214,9 +215,9 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs
warn!("Gallery on page {from:?} references nonexistent image {file:?}");
continue;
}
- let large = format!("{root}images/large/{file}");
- // let small = format!("{root}images/small/{file}");
- let thumb = format!("{root}images/thumb/{file}");
+ let large = sanitize_text(&format!("{root}images/large/{file}"), false);
+ // let small = sanitize_text(&format!("{root}images/small/{file}"), false);
+ let thumb = sanitize_text(&format!("{root}images/thumb/{file}"), false);
html!("<a href='{large}'><img src='{thumb}' /></a>");
}),
"gallery-nav" => wrap!("div", "class='gallery-nav'", for line in content.lines() {
@@ -226,7 +227,7 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs
let image = image.trim();
let ParsedLink { path, class, label } = parse_internal_link(name, page, website);
if website.has_image(image) {
- let thumb = format!("{root}images/thumb/{image}");
+ let thumb = sanitize_text(&format!("{root}images/thumb/{image}"), false);
html!("<a href='{path}' class='{class}'><img src='{thumb}'/><p>{label}</p></a>")
} else {
warn!("Gallery-nav on page {from:?} references nonexistent image {image:?}");
@@ -406,13 +407,19 @@ fn sanitize_text(text: &str, fancy: bool) -> String {
},
'<' => output.push_str("&lt;"),
'>' => output.push_str("&gt;"),
- '"' if fancy => match prev.is_whitespace() {
- true => output.push('“'),
- false => output.push('”'),
+ '"' => match fancy {
+ true => match prev.is_whitespace() {
+ true => output.push('“'),
+ false => output.push('”'),
+ }
+ false => output.push_str("&#34;"),
},
- '\'' if fancy => match prev.is_whitespace() {
- true => output.push('‘'),
- false => output.push('’'),
+ '\'' => match fancy {
+ true => match prev.is_whitespace() {
+ true => output.push('‘'),
+ false => output.push('’'),
+ }
+ false => output.push_str("&#39;"),
},
'-' if fancy => match prev.is_whitespace() && next.is_whitespace() {
true => match i > 0 {