]> git.plutz.net Git - cgilite/commitdiff
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 f227d27fe47f65832bf9aefbec77dbcb4e262612..13cdb3cdc347f35ffd507a2d4fcd9c1dc6f5a2e0 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='';;