From: Paul Hänsch Date: Tue, 15 Sep 2026 15:56:45 +0000 (+0200) Subject: general improved performance for POST/GET, performance switch for large HTML escapes X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=ca8a3d6191c280af0e9841b079521ed085a2af4e;p=cgilite general improved performance for POST/GET, performance switch for large HTML escapes --- diff --git a/cgilite.sh b/cgilite.sh index ac23f40..f261f9c 100755 --- a/cgilite.sh +++ b/cgilite.sh @@ -224,10 +224,10 @@ cgilite_count(){ } 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 + \ )" @@ -294,19 +294,38 @@ HTML(){ # 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(){