]> git.plutz.net Git - cgilite/blobdiff - cgi.sh
derive structure which avoids multiple execution
[cgilite] / cgi.sh
diff --git a/cgi.sh b/cgi.sh
index e994daa99d2ff50d68eeaab5703c2ec8a01d611d..4f4cb509ed05458857209495f2d7d98e378dadbd 100755 (executable)
--- a/cgi.sh
+++ b/cgi.sh
@@ -40,14 +40,13 @@ cgi_post() {  # parse HTTP POST string
     key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\1:')"
     val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\2:')"
     value="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g;')")"
-    if [ -n "${_POST[$key]}" ]; then
+    n=''
+    if [ -n "${_POST[$key$n]}" ]; then
       n=0
       while [ -n "${_POST[$key$n]}" ]; do n=$(($n + 1)); done
-      _POST[$key$n]="$value"
-    else
-      _POST[$key]="$value"
     fi
-    debug "_POST[$key] => $value"
+    _POST[$key$n]="$value"
+    debug "_POST[$key$n] => $value"
   done
 }
 
@@ -71,20 +70,25 @@ cgi_cookie() { # Parse GET data from referer
   done
 }
 
-urlsave(){
+urlsafe(){
   printf %s "$*" \
   | sed 's;%;%25;g;
-         s; ;%20;g;
-         s;!;%21;g;
-         s;";%22;g;
-         s;&;%26;g;
-         s;(;%28;g;
-         s;);%29;g;
-         s;:;%3a;g
+         s;\?;%3f;g;
+         s;#;%23;g;
          s;<;%3c;g;
          s;>;%3e;g;
-         s;'\'';%27;g;
-         s;\?;%3f;g;'
+         s;&;%26;g;
+         s;";%22;g;
+         s;'\'';%27;g;'
+}
+
+htmlsafe(){
+  printf %s "$*" \
+  | sed 's;<;\&lt\;;g;
+         s;>;\&gt\;;g;
+         s;&;\&amp\;;g;
+         s;";\&quot\;;g;
+         s;'\'';\&apos\;;g;'
 }
 
 redirect(){