We now have a function to encode HTML special characters

This commit is contained in:
Nathaniel Landau
2015-10-10 01:35:37 -04:00
parent 9eee711af7
commit 4a8ceca0e1

View File

@@ -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 <string>
echo "${1}" | sed -f "${SOURCEPATH}/htmlEncode.sed"
}
urlencode() {
# URL encoding/decoding from: https://gist.github.com/cdown/1163649