for test prefix string (doesnt allow injection of commands), improve printf fmt string - static-site-scripts - static site generator shellscripts
(HTM) git clone git://git.codemadness.org/static-site-scripts
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 501f05e74049ca84d3a314c4e740c0b38671fe60
(DIR) parent 6f70295baba7ccde865f0913ced236e5d05cc07e
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sun, 11 Oct 2015 16:54:58 +0200
for test prefix string (doesnt allow injection of commands), improve printf fmt string
Diffstat:
M generate.sh | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
---
(DIR) diff --git a/generate.sh b/generate.sh
@@ -74,21 +74,21 @@ pageread() {
dateupdated=$(printf '%s' "${timeupdated}" | cut -b 1-10)
# if ${id} is empty and title is set: create id based on title.
- if [ "${id}" = "" ] && [ ! "${title}" = "" ]; then
+ if [ x"${id}" = x"" ] && [ ! x"${title}" = x"" ]; then
id=$(makeid "${title}")
fi
- if [ "${id}" = "" ]; then
- printf '%s\n' "Warning: \$id or \$title not set in \"${meta}\", skipping..." >&2
- continue
+ if [ x"${id}" = x"" ]; then
+ printf 'Warning: $id or $title not set in "%s", skipping...\n' "${meta}" >&2
+ return
fi
- if [ "${url}" = "" ]; then
+ if [ x"${url}" = x"" ]; then
url="${id}.html"
fi
outfile="${id}.html"
urlfull="${siteurlfull}/${outfile}"
filename=""
# ${content} not set; try data from filetypes.
- if [ "${content}" = "" ]; then
+ if [ x"${content}" = x"" ]; then
if [ -f "${pagesdir}/${basename}.html" ]; then
filename="${pagesdir}/${basename}.html"
content=$(cat "${filename}")
@@ -98,14 +98,14 @@ pageread() {
fi
fi
created="<strong>Created on:</strong> ${datecreated}<br/>"
- if [ ! "${datecreated}" = "${dateupdated}" ]; then
+ if [ ! x"${datecreated}" = x"${dateupdated}" ]; then
created="${created}<strong>Last update on:</strong> ${dateupdated}<br/>"
fi
}
pageheader() {
# prefix page title with site title, make sure its neatly formatted.
- if [ "${title}" = "" ]; then
+ if [ x"${title}" = x"" ]; then
pagetitle="${sitetitle}"
else
pagetitle="${title} - ${sitetitle}"
@@ -169,12 +169,12 @@ pagefooter() {
}
if [ ! -d "${pagesdir}" ]; then
- printf '%s\n' "Error: pages directory \"${pagesdir}\" not found." >&2
+ printf 'Error: pages directory "%s" not found.\n' "${pagesdir}" >&2
exit 1
fi
# process single page as argument (handy for testing a single page).
-if [ ! "$1" = "" ]; then
+if [ ! x"$1" = x"" ]; then
pagereset
pageread "$1"
pagecontent