Skip to content

Commit 295be23

Browse files
committed
FIX: DECODE-URL does not support UNICODE
Fixes: metaeducation/rebol-issues#2380
1 parent 7517d0b commit 295be23

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/mezz/sys-ports.r

+6-5
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ make-port*: func [
8484
digits: [1 5 digit]
8585
alpha-num: make bitset! [#"a" - #"z" #"A" - #"Z" #"0" - #"9"]
8686
scheme-char: insert copy alpha-num "+-."
87-
path-char: insert copy alpha-num "/=+-_.;:&$@%*',~?| []()^"" ; !!! note: space allowed
88-
user-char: insert copy alpha-num "=+-_.;&$%*,'#|"
89-
pass-char: complement make bitset! "^/ ^-@"
87+
path-char: complement make bitset! "#"
88+
user-char: complement make bitset! ":@"
89+
host-char: complement make bitset! ":/"
9090
s1: s2: none ; in R3, input datatype is preserved - these are now URL strings!
9191
out: []
9292
emit: func ['w v] [reduce/into [to set-word! w if :v [to string! :v]] tail out]
@@ -107,7 +107,7 @@ make-port*: func [
107107

108108
; optional host [:port]
109109
opt [
110-
copy s1 any user-char
110+
copy s1 any host-char
111111
opt [#":" copy s2 digits (compose/into [port-id: (to integer! s2)] tail out)]
112112
(unless empty? s1 [attempt [s1: to tuple! s1] emit host s1])
113113
]
@@ -117,13 +117,14 @@ make-port*: func [
117117
opt [copy s1 some path-char (emit path s1)]
118118

119119
; optional bookmark
120-
opt [#"#" copy s1 some path-char (emit tag s1)]
120+
opt [#"#" copy s1 to end (emit tag s1)]
121121
]
122122

123123
decode-url: func ["Decode a URL according to rules of sys/*parse-url." url] [
124124
--- "This function is bound in the context of sys/*parse-url."
125125
out: make block! 8
126126
parse/all url rules
127+
probe out
127128
out
128129
]
129130
]

src/tests/units/port-test.r3

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ Rebol [
88

99
~~~start-file~~~ "port"
1010

11+
===start-group=== "decode-url"
12+
;@@ https://github.com/rebol/rebol-issues/issues/2380
13+
--test-- "decode-url-unicode"
14+
url: decode-url http://example.com/get?q=ščř#kovtička
15+
--assert url/scheme = 'http
16+
--assert url/host = "example.com"
17+
--assert url/path = "/get?q=ščř"
18+
--assert url/tag = "kovtička"
19+
--test-- "decode-url-unicode"
20+
url: decode-url http://švéd:břéťa@example.com:8080/get?q=ščř#kovtička
21+
--assert url/scheme = 'http
22+
--assert url/user = "švéd"
23+
--assert url/pass = "břéťa"
24+
--assert url/host = "example.com"
25+
--assert url/port-id = 8080
26+
--assert url/path = "/get?q=ščř"
27+
--assert url/tag = "kovtička"
28+
29+
===end-group===
30+
1131
===start-group=== "directory port"
1232
;@@ https://github.com/rebol/rebol-issues/issues/2320
1333
--test-- "port-issue-2320"

0 commit comments

Comments
 (0)