]> gitweb.factorcode.org Git - factor.git/commitdiff
gopher: use url encoding and decoding to work with weird filenames.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 2 Nov 2016 18:11:53 +0000 (11:11 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 2 Nov 2016 18:11:53 +0000 (11:11 -0700)
extra/gopher/gopher.factor
extra/gopher/server/server.factor

index 18d7a65b96d67ec3029145256e48d578f9d6ff99..5820c784f7dd2db407dee277cc094b47726b7418 100644 (file)
@@ -52,7 +52,7 @@ ERROR: not-a-gopher-url url ;
     >url dup protocol>> "gopher" = [ not-a-gopher-url ] unless {
         [ host>> ]
         [ port>> 70 or <inet> binary ]
-        [ path>> rest [ "1/" ] when-empty ]
+        [ path>> rest url-encode [ "1/" ] when-empty ]
         [ query>> [ assoc>query url-decode "?" glue ] when* ]
     } cleave '[
         1 minutes input-stream get set-timeout
index d48aa31e15a0fe9f604573ea98e412ddc7d6895e..1042fa3648d18530ea337071476287313f1d0fc4 100644 (file)
@@ -5,7 +5,7 @@ USING: accessors calendar combinators combinators.short-circuit
 formatting fry io io.directories io.encodings.binary
 io.encodings.string io.encodings.utf8 io.files io.files.info
 io.files.types io.pathnames io.servers kernel locals math
-mime.types sequences splitting strings ;
+mime.types sequences splitting strings urls.encoding ;
 
 IN: gopher.server
 
@@ -72,6 +72,7 @@ TUPLE: gopher-server < threaded-server
             ] [
                 path prepend-path
                 server serving-directory>> ?head drop
+                url-encode
             ] bi
             server serving-hostname>>
             server insecure>>
@@ -91,7 +92,7 @@ TUPLE: gopher-server < threaded-server
 
 : read-gopher-path ( -- path )
     readln dup [ "\t\r\n" member? ] find drop [ head ] when*
-    trim-tail-separators ;
+    trim-tail-separators url-decode ;
 
 M: gopher-server handle-client*
     dup serving-directory>> read-gopher-path append-path