]> gitweb.factorcode.org Git - factor.git/commitdiff
urls: RFC 3986 (5.2.4. Remove Dot Segments)
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 12 Mar 2021 04:19:14 +0000 (20:19 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 12 Mar 2021 04:19:14 +0000 (20:19 -0800)
basis/urls/urls.factor

index a0edf38a84cee17627c28b7831109497784273ef..64cc9d1e9067f231fbd81535656e92e5ed97a7ee 100644 (file)
@@ -146,6 +146,13 @@ M: url present
         } cleave
     ] "" make ;
 
+: remove-dot-segments ( path -- path' )
+    "/" split "." swap remove [
+        { ".." } split1 [
+            [ [ { } ] [ but-last ] if-empty ] dip append t
+        ] [ f ] if*
+    ] loop "/" join [ f ] when-empty ;
+
 PRIVATE>
 
 : url-append-path ( path1 path2 -- path )
@@ -155,7 +162,7 @@ PRIVATE>
         { [ over "/" tail? ] [ append ] }
         { [ "/" pick subseq-start not ] [ nip ] }
         [ [ "/" split1-last drop "/" ] dip 3append ]
-    } cond ;
+    } cond remove-dot-segments ;
 
 <PRIVATE