commit bfd9735e7511f59bd92540ecf9a9b4011b737798
parent 87e0f3ef2bf68624e87f308a235a41d546f7bd7f
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Thu, 15 Sep 2022 16:51:02 -0400
Properly escape title and description fields
Previously, if you had a '/' or some other character recognized by sed
as a special regex character in the title or description of a page, that
page would fail to build. This adds a couple lines that runs those bits
of text through a separate sed command to escape any such special
characters and prevent those issues.
Diffstat:
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/sbs b/sbs
@@ -99,7 +99,8 @@ parse_configuration()
}
# Construct a complete atom feed from all blog posts
-genfeed() {
+genfeed()
+{
{ printf '<?xml version="1.0" encoding="utf-8"?>\n'
printf '<feed xmlns="http://www.w3.org/2005/Atom">\n'
printf "\t<title>%s</title>\n" "$siteName"
@@ -199,6 +200,12 @@ build()
title=${title:-$(lowdown -X title "$file")}
description=${description:-$(lowdown -X summary "$file")}
+ # Escapes characters from text that might interfere with sed
+ title=$(echo $title | sed 's/\\/\\\\/g; s/\//\\\//g; s/\^/\\^/g;
+ s/\[/\\[/g; s/\*/\\*/g; s/\./\\./g; s/\$/\\$/g')
+ description=$(echo $description | sed 's/\\/\\\\/g; s/\//\\\//g;
+ s/\^/\\^/g; s/\[/\\[/g; s/\*/\\*/g; s/\./\\./g; s/\$/\\$/g')
+
# Build and process the output document
lowdown $buildOptions "$file" \
| cat "templates/header.html" - "templates/footer.html" \