From 4a8ceca0e1650733c35f05e45e412174c78d3f69 Mon Sep 17 00:00:00 2001 From: Nathaniel Landau Date: Sat, 10 Oct 2015 01:35:37 -0400 Subject: [PATCH] We now have a function to encode HTML special characters --- lib/sharedFunctions.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/sharedFunctions.sh b/lib/sharedFunctions.sh index 0731798..d9d3e82 100755 --- a/lib/sharedFunctions.sh +++ b/lib/sharedFunctions.sh @@ -48,7 +48,7 @@ function readFile() { # ------------------------------------------------------ # usage: var=$(escape "String") # ------------------------------------------------------ -escape() { echo $@ | sed 's/[]\.|$(){}?+*^]/\\&/g'; } +escape() { echo "${@}" | sed 's/[]\.|$(){}?+*^]/\\&/g'; } # needSudo # ------------------------------------------------------ @@ -520,6 +520,12 @@ htmlDecode() { echo "${1}" | sed -f "${SOURCEPATH}/htmlDecode.sed" } +htmlEncode() { + # Encode HTML characters with sed + # Usage: htmlEncode + echo "${1}" | sed -f "${SOURCEPATH}/htmlEncode.sed" +} + urlencode() { # URL encoding/decoding from: https://gist.github.com/cdown/1163649