]> git.plutz.net Git - shellwiki/commitdiff
Squashed 'cgilite/' changes from 221c2b7d..ca8a3d61
authorPaul Hänsch <paul@plutz.net>
Tue, 15 Sep 2026 15:58:47 +0000 (17:58 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 15 Sep 2026 15:58:47 +0000 (17:58 +0200)
ca8a3d61 general improved performance for POST/GET, performance switch for large HTML escapes
b233ce08 improved attribute parsing in headlines

git-subtree-dir: cgilite
git-subtree-split: ca8a3d6191c280af0e9841b079521ed085a2af4e

cgilite.sh
markdown.awk

index ac23f40eb664be2d4fb6d0fc14ae3dff755ace51..f261f9c195c12d8cc53d6b374382a0f46b5e855d 100755 (executable)
@@ -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}&amp;";       str="${str#?}";;
-    \<*) out="${out}&lt;";        str="${str#?}";;
-    \>*) out="${out}&gt;";        str="${str#?}";;
-    \"*) out="${out}&quot;";      str="${str#?}";;
-    \'*) out="${out}&#x27;";      str="${str#?}";;
-    \[*) out="${out}&#x5B;";      str="${str#?}";;
-    \]*) out="${out}&#x5D;";      str="${str#?}";;
-    "${CR}"*) out="${out}&#x0D;"; str="${str#?}";;
-    "${BR}"*) out="${out}&#x0A;"; 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}&amp;";       str="${str#?}";;
+      \<*) out="${out}&lt;";        str="${str#?}";;
+      \>*) out="${out}&gt;";        str="${str#?}";;
+      \"*) out="${out}&quot;";      str="${str#?}";;
+      \'*) out="${out}&#x27;";      str="${str#?}";;
+      \[*) out="${out}&#x5B;";      str="${str#?}";;
+      \]*) out="${out}&#x5D;";      str="${str#?}";;
+      "${CR}"*) out="${out}&#x0D;"; str="${str#?}";;
+      "${BR}"*) out="${out}&#x0A;"; 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;&;\&amp\;;g;
+    s;<;\&lt\;;g;
+    s;>;\&gt\;;g;
+    s;";\&quot\;;g;
+    s;\[;\&#x5B\;;g;
+    s;\];\&#x5D\;;g;
+    s;\r;\&#x0D\;;g;
+    s;\n;\&#x0A\;;g;
+    s;'\'';\&#x27\;;g;
+  '
 }
 
 URL(){
index d1f6616dd7aa7e93131230a25edc950900ecab5c..b60285e68f2b4c613c2c066a94094da6f5004dc7 100755 (executable)
@@ -650,7 +650,8 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code,
     # First Order Heading H1 + Attrib
     } else if ( match( block, "^([^\n]+)([ \t]*"rattr")\n===+(\n|$)" ) ) {
       len = RLENGTH; text = attrib = block;
-      sub(/([ \t]*\{([^\}\n]+)\})\n===+(\n.*)?$/, "", text);
+      sub("([ \t]*"rattr")\n===+(\n.*)?$", "", text);
+      sub(/\n===+(\n.*)?$/, "", attrib);
       attrib = _attr(attrib);
 
       ret = ret headline(1, text, attrib) ; block = substr( block, len + 1 );
@@ -667,7 +668,8 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code,
     # Second Order Heading H2 + Attrib
     } else if ( match( block, "^([^\n]+)([ \t]*"rattr")\n---+(\n|$)" ) ) {
       len = RLENGTH; text = attrib = block;
-      sub(/([ \t]*\{([^\}\n]+)\})\n---+(\n.*)?$/, "", text);
+      sub("([ \t]*"rattr")\n---+(\n.*)?$", "", text);
+      sub(/\n---+(\n.*)?$/, "", attrib);
       attrib = _attr(attrib);
 
       ret = ret headline(2, text, attrib) ; block = substr( block, len + 1);
@@ -686,7 +688,7 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code,
       len = RLENGTH; text = attrib = substr(block, 1, len);
       match(block, /^##?#?#?#?#?[^#]/); n = RLENGTH - 1;
       text = substr(text, n + 1); sub(/^[ \t]*/, "", text);
-      sub(/[ \t]*#*([ \t]*\{([a-zA-Z \t-]*)\})(\n.*)?$/, "", text);
+      sub("[ \t]*#*([ \t]*"rattr")(\n.*)?$", "", text);
 
       attrib = _attr(attrib);