]> gitweb.factorcode.org Git - factor.git/commitdiff
urls: fix for unicode url parsing.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 4 Mar 2021 22:56:15 +0000 (14:56 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 4 Mar 2021 22:56:15 +0000 (14:56 -0800)
basis/urls/urls-tests.factor
basis/urls/urls.factor

index d6d73ec4599cd7a80d0d5457f811f4d6a922dde4..de7e86e6fa2182e52e588ad49fcf869b7bf987ce 100644 (file)
@@ -163,6 +163,18 @@ urls [
     swap [ 1array ] [ [ present ] curry ] bi* unit-test
 ] assoc-each
 
+{ T{ url
+    { protocol "http" }
+    { username "ш" }
+    { password "ш" }
+    { host "ш.com" }
+    { port 1234 }
+    { path "/ш" }
+    { query LH{ { "ш" "ш" } } }
+    { anchor "ш" }
+  } }
+[ "http://ш:ш@ш.com:1234/ш?ш=ш#ш" >url ] unit-test
+
 { T{ url
     { protocol "https" }
     { host "www.google.com" }
index 706cb2254444722971bba40160986a1b7f4cb717..1660bebddcb8114cb58fb522c1d828fbe7dbb3bd 100644 (file)
@@ -2,11 +2,11 @@
 ! See http://factorcode.org/license.txt for BSD license.
 
 USING: accessors ascii assocs combinators
-combinators.short-circuit fry io.pathnames io.sockets
-io.sockets.secure kernel lexer linked-assocs make math
-math.parser multiline namespaces peg.ebnf present sequences
-sequences.generalizations splitting strings strings.parser
-urls.encoding vocabs.loader ;
+combinators.short-circuit fry io.encodings.string
+io.encodings.utf8 io.pathnames io.sockets io.sockets.secure
+kernel lexer linked-assocs make math math.parser multiline
+namespaces peg.ebnf present sequences sequences.generalizations
+splitting strings strings.parser urls.encoding vocabs.loader ;
 
 IN: urls
 
@@ -73,7 +73,7 @@ url      = (protocol ":"~)?
 PRIVATE>
 
 M: string >url
-    [ <url> ] dip parse-url 5 firstn {
+    [ <url> ] dip utf8 encode parse-url 5 firstn {
         [ >lower >>protocol ]
         [
             [
@@ -100,7 +100,7 @@ M: pathname >url string>> >url ;
 
 : unparse-username-password ( url -- )
     dup username>> dup [
-        % password>> [ ":" % % ] when* "@" %
+        url-encode % password>> [ ":" % url-encode % ] when* "@" %
     ] [ 2drop ] if ;
 
 : url-port ( url -- port/f )