From 29ffca829925a30ff920c79f94ec1b3dbf48f8fa Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Wed, 21 May 2025 13:09:11 +1200 Subject: Sanitize quotes in file paths --- src/generate_html.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src/generate_html.rs') 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!( "
{label}
"), @@ -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!(""); }), "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!("

{label}

") } 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("<"), '>' => output.push_str(">"), - '"' 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("""), }, - '\'' 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("'"), }, '-' if fancy => match prev.is_whitespace() && next.is_whitespace() { true => match i > 0 { -- cgit v1.2.3-70-g09d2