Skip to content

Commit a4e529a

Browse files
committed
Fix wide-character decoding in URLs.
1 parent 0295d44 commit a4e529a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

racket/lib/collects/net/uri-codec.rkt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,21 @@ See more in PR8831.
167167
;; vector string -> string
168168
(define (decode table str)
169169
(define max-ascii (integer->char ascii-size))
170+
;; internal-decode : list -> listof[byte]
170171
(define (internal-decode l)
171172
(if (null? l) '()
172173
(let* ([c (car l)] [l (cdr l)]
173174
[hex (and (equal? #\% c) (pair? l) (pair? (cdr l))
174175
(string->number (string (car l) (cadr l)) 16))])
175-
(if hex (cons hex (internal-decode (cddr l)))
176-
(cons (if (char<? c max-ascii)
177-
(vector-ref table (char->integer c))
178-
;; This should probably error, but strings to be decoded
179-
;; might come from misbehaving sources; maybe it's better
180-
;; to add some parameter for a permissive mode
181-
(bytes->list (string->bytes/utf-8 (string c))))
182-
(internal-decode l))))))
176+
(if hex
177+
(cons hex (internal-decode (cddr l)))
178+
(append (if (char<? c max-ascii)
179+
(list (vector-ref table (char->integer c)))
180+
;; This should probably error, but strings to be decoded
181+
;; might come from misbehaving sources; maybe it's better
182+
;; to add some parameter for a permissive mode
183+
(bytes->list (string->bytes/utf-8 (string c))))
184+
(internal-decode l))))))
183185
(bytes->string/utf-8 (apply bytes (internal-decode (string->list str)))))
184186

185187
;; Utility for defining codecs

0 commit comments

Comments
 (0)