# Also escape [, ], and \n for use in html-sh
local str out
[ $# -eq 0 ] && str="$(cat)" || str="$*"
- while [ "$str" ]; do
- case $str in
- \&*) out="${out}&";;
- \<*) out="${out}<";;
- \>*) out="${out}>";;
- \"*) out="${out}"";;
- \'*) out="${out}'";;
- \[*) out="${out}[";;
- \]*) out="${out}]";;
- "${CR}"*) out="${out}
";;
- "${BR}"*) out="${out}
";;
- *) out="${out}${str%"${str#?}"}";;
- esac
- str="${str#?}"
- done
+ while [ "$str" ]; do case $str in
+ \&*) out="${out}&"; str="${str#?}";;
+ \<*) out="${out}<"; str="${str#?}";;
+ \>*) out="${out}>"; str="${str#?}";;
+ \"*) out="${out}""; str="${str#?}";;
+ \'*) out="${out}'"; str="${str#?}";;
+ \[*) out="${out}["; str="${str#?}";;
+ \]*) out="${out}]"; str="${str#?}";;
+ "${CR}"*) out="${out}
"; str="${str#?}";;
+ "${BR}"*) out="${out}
"; str="${str#?}";;
+ *) out="${out}${str%%[]&<>\"\'[]*}"; str="${str#"${str%%[]&<>\"\'[]*}"}";;
+ esac; done
printf %s "$out"
}
# Escape pathes, so they can be used in link tags and HTTP Headers
local str out
[ $# -eq 0 ] && str="$(cat)" || str="$*"
- while [ "$str" ]; do
- case $str in
- \&*) out="${out}%26";;
- \"*) out="${out}%22";;
- \'*) out="${out}%27";;
- \?*) out="${out}%3F";;
- \#*) out="${out}%23";;
- \[*) out="${out}%5B";;
- \]*) out="${out}%5D";;
- \ *) out="${out}%20";;
- " "*) out="${out}%09";;
- "${CR}"*) out="${out}%0D";;
- "${BR}"*) out="${out}%0A";;
- %*) out="${out}%25";;
- *) out="${out}${str%"${str#?}"}";;
- esac
- str="${str#?}"
- done
+ while [ "$str" ]; do case $str in
+ \&*) out="${out}%26"; str="${str#?}";;
+ \"*) out="${out}%22"; str="${str#?}";;
+ \'*) out="${out}%27"; str="${str#?}";;
+ \?*) out="${out}%3F"; str="${str#?}";;
+ \#*) out="${out}%23"; str="${str#?}";;
+ \[*) out="${out}%5B"; str="${str#?}";;
+ \]*) out="${out}%5D"; str="${str#?}";;
+ \ *) out="${out}%20"; str="${str#?}";;
+ " "*) out="${out}%09"; str="${str#?}";;
+ "${CR}"*) out="${out}%0D"; str="${str#?}";;
+ "${BR}"*) out="${out}%0A"; str="${str#?}";;
+ %*) out="${out}%25"; str="${str#?}";;
+ *) out="${out}${str%%[]&\"\'# ${CR}${BR}[]*}"; str="${str#"${str%%[]&\"\'# ${CR}${BR}[]*}"}";;
+ esac; done
printf %s "$out"
}