]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/urls/urls.factor
urls: improve remove-dot-segments and test lots of cases.
[factor.git] / basis / urls / urls.factor
index 64cc9d1e9067f231fbd81535656e92e5ed97a7ee..0347cd729295d9ef8dfc395df44a852453e3cac7 100644 (file)
@@ -147,11 +147,13 @@ M: url present
     ] "" make ;
 
 : remove-dot-segments ( path -- path' )
-    "/" split "." swap remove [
-        { ".." } split1 [
-            [ [ { } ] [ but-last ] if-empty ] dip append t
-        ] [ f ] if*
-    ] loop "/" join [ f ] when-empty ;
+    "/./" "/" replace
+    [ "/../" split1 ] [ [ "/" split1-last drop ] dip "/" glue ] while*
+    "/.." ?tail [ "/" split1-last drop "/" append ] when
+    "../" ?head [ "/" prepend ] when
+    "./" ?head [ "/" prepend ] when
+    "/." ?tail [ "/" append ] when
+    [ "/" ] when-empty ;
 
 PRIVATE>