path cononicalization function (works on non-exist pathes unlike realpath)
authorPaul Hänsch <paul@plutz.net>
Thu, 5 Jul 2018 12:40:11 +0000 (14:40 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 5 Jul 2018 12:40:11 +0000 (14:40 +0200)
cgilite.sh

index f227d27..13cdb3c 100755 (executable)
@@ -50,7 +50,7 @@ HEX_DECODE(){
   ')"
 }
 
-if [ -z "$REQUEST_METHOD" -a -z "$SERVER_PROTOCOL" ]; then
+if [ -z "$REQUEST_METHOD" ]; then
   # no webserver variables means we are running via inetd / ncat
   # so use builtin web server
 
@@ -173,6 +173,18 @@ URL(){
   | tr , %
 }
 
+PATH(){
+  printf %s "$1" \
+  | sed -r 's;^.*$;/&/;; s;/+;/;g;
+            :X;
+            s;^/../;/;; s;/./;/;g;
+            tX;
+            s;/[^/]+/../;/;;
+            tX;
+            s;^(/.*)/$;\1;'
+}
+
+
 SET_COOKIE(){
   case "$1" in
     ''|0|session) expire='';;