}
cgilite_value(){
- local str="&$1" name="$2" cnt="${3:-1}"
+ local ref="&$1" str="&$1" name="$2" cnt="${3:-1}"
while [ $cnt -gt 0 ]; do
- [ "${str}" = "${str#*&${name}=}" ] && return 1
str="${str#*&${name}=}"
+ [ "${str}" = "${ref}" ] && return 1 || ref="${str}"
cnt=$((cnt - 1))
done
HEX_DECODE % "$(printf %s "${str%%&*}" |tr + \ )"
# 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}&"; 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%%[]&<>\"\'${CR}${BR}[]*}"; str="${str#"${str%%[]&<>\"\'${CR}${BR}[]*}"}";;
- esac; done
- printf %s "$out"
+ if [ "${#str}" -ge 1000 ]; then
+ HTML_large "$str"
+ else
+ 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%%[]&<>\"\'${CR}${BR}[]*}"; str="${str#"${str%%[]&<>\"\'${CR}${BR}[]*}"}";;
+ esac; done
+ printf %s "$out"
+ fi
+}
+
+HTML_large(){
+ # Better performance for large strings
+ printf %s "$*" | sed -zE '
+ s;&;\&\;;g;
+ s;<;\<\;;g;
+ s;>;\>\;;g;
+ s;";\"\;;g;
+ s;\[;\[\;;g;
+ s;\];\]\;;g;
+ s;\r;\
\;;g;
+ s;\n;\
\;;g;
+ s;'\'';\'\;;g;
+ '
}
URL(){