@@ -13,7 +13,7 @@ REBOL [
13
13
See: http://www.apache.org/licenses/LICENSE-2.0
14
14
}
15
15
Version: 0.5.4
16
- Date: 12 -Jul-2024
16
+ Date: 15 -Jul-2024
17
17
File: %prot-http.r3
18
18
Purpose: {
19
19
This program defines the HTTP protocol scheme for REBOL 3.
@@ -41,6 +41,7 @@ REBOL [
41
41
0.5.1 12-Jun-2023 "Oldes" "FEAT: anonymize authentication tokens in log"
42
42
0.5.2 22-Jul-2023 "Oldes" "FEAT: support for optional Brotli encoding"
43
43
0.5.3 11-Jul-2024 "Oldes" "FIX: redirection with a missing slash in the location field"
44
+ 0.5.4 15-Jul-2024 "Oldes" "FIX: HTTP query validated when building a request"
44
45
]
45
46
]
46
47
@@ -253,6 +254,22 @@ throw-http-error: func [
253
254
][ do error ]
254
255
]
255
256
257
+ escape-query: function/with [
258
+ ;; "Escapes all chars which are not allowed in the HTTP query part (if not yet escaped)"
259
+ query [any-string! ]
260
+ ][
261
+ parse query [some [
262
+ some allowed
263
+ | #"%" 2 numeric ;; already escaped
264
+ | change #" " #"+"
265
+ | change set c: skip (ajoin [#"%" enbase to binary! c 16 ])
266
+ ]]
267
+ query
268
+ ][
269
+ numeric: system/catalog/bitsets/numeric
270
+ allowed: charset [#"a" -#"z" #"A" -#"Z" #"0" -#"9" "-~!@*/|\;,._()[]{}+=?~" ]
271
+ ]
272
+
256
273
make-http-request : func [
257
274
"Create an HTTP request (returns binary!)"
258
275
spec [block! object! ] "Request specification from an opened port"
@@ -270,7 +287,7 @@ make-http-request: func [
270
287
mold as url! :path ;; `mold as url!` is used because it produces correct escaping
271
288
]
272
289
if :target [append request mold as url! :target ]
273
- if :query [append append request #"?" :query ]
290
+ if :query [append append request #"?" escape-query :query ]
274
291
275
292
append request " HTTP/1.1^M^/ "
276
293
0 commit comments