Skip to content

Commit

Permalink
Fix wide-character decoding in URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
samth committed Jul 5, 2013
1 parent 0295d44 commit a4e529a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions racket/lib/collects/net/uri-codec.rkt
Expand Up @@ -167,19 +167,21 @@ See more in PR8831.
;; vector string -> string
(define (decode table str)
(define max-ascii (integer->char ascii-size))
;; internal-decode : list -> listof[byte]
(define (internal-decode l)
(if (null? l) '()
(let* ([c (car l)] [l (cdr l)]
[hex (and (equal? #\% c) (pair? l) (pair? (cdr l))
(string->number (string (car l) (cadr l)) 16))])
(if hex (cons hex (internal-decode (cddr l)))
(cons (if (char<? c max-ascii)
(vector-ref table (char->integer c))
;; This should probably error, but strings to be decoded
;; might come from misbehaving sources; maybe it's better
;; to add some parameter for a permissive mode
(bytes->list (string->bytes/utf-8 (string c))))
(internal-decode l))))))
(if hex
(cons hex (internal-decode (cddr l)))
(append (if (char<? c max-ascii)
(list (vector-ref table (char->integer c)))
;; This should probably error, but strings to be decoded
;; might come from misbehaving sources; maybe it's better
;; to add some parameter for a permissive mode
(bytes->list (string->bytes/utf-8 (string c))))
(internal-decode l))))))
(bytes->string/utf-8 (apply bytes (internal-decode (string->list str)))))

;; Utility for defining codecs
Expand Down

0 comments on commit a4e529a

Please sign in to comment.