Further explain silent acceptance of unencoded characters.

Also highlight the two tests that use that.
(cherry picked from commit 8d55b892ec)
This commit is contained in:
Eli Barzilay 2013-07-05 20:20:43 -04:00 committed by Ryan Culpepper
parent cc655dc13b
commit ec2acb8bc0
2 changed files with 11 additions and 5 deletions

View File

@ -177,9 +177,12 @@ See more in PR8831.
(cond [hex (cons hex rest)] (cond [hex (cons hex rest)]
[(char<? c max-ascii) (cons (vector-ref table (char->integer c)) [(char<? c max-ascii) (cons (vector-ref table (char->integer c))
rest)] rest)]
;; This should probably error, but strings to be decoded ;; This should probably error, but strings to be decoded might
;; might come from misbehaving sources; maybe it's ;; come from misbehaving sources; maybe it's better to add some
;; better to add some parameter for a permissive mode ;; parameter for a permissive mode; one source of such bad URLs
;; is user-defined strings where the string is entered directly
;; and not properly encoded -- similar justification to
;; browsers accepting unencoded chars in manually entered URLs.
[else (append (bytes->list (string->bytes/utf-8 (string c))) [else (append (bytes->list (string->bytes/utf-8 (string c)))
(internal-decode l))])))) (internal-decode l))]))))
(bytes->string/utf-8 (apply bytes (internal-decode (string->list str))))) (bytes->string/utf-8 (apply bytes (internal-decode (string->list str)))))

View File

@ -44,7 +44,7 @@
=> (->vec expected))) => (->vec expected)))
(provide tests) (provide tests)
(module+ main (tests)) (module+ main (test do (tests)))
(define (tests) (define (tests)
(test (test
;; Test the current-proxy-servers parameter can be set ;; Test the current-proxy-servers parameter can be set
@ -254,9 +254,12 @@
(test-s->u #("mailto" #f #f #f #f (#("robby@racket-lang.org")) () #f) (test-s->u #("mailto" #f #f #f #f (#("robby@racket-lang.org")) () #f)
"mailto:robby@racket-lang.org") "mailto:robby@racket-lang.org")
;; The following two tests are not really correct: they rely on the URL
;; decoding silently passing un-encoded text as is instead of barfing. (Eg,
;; using these URLs in a browser and then copy-pasting it from the address
;; should get you a properly encoded string instead.)
(test (string->url/vec "http://www.drscheme.org?bar=馨慧") (test (string->url/vec "http://www.drscheme.org?bar=馨慧")
#("http" #f "www.drscheme.org" #f #f () ((bar . "馨慧")) #f)) #("http" #f "www.drscheme.org" #f #f () ((bar . "馨慧")) #f))
(test (string->url/vec "http://www.drscheme.org?bár=é") (test (string->url/vec "http://www.drscheme.org?bár=é")
=> #("http" #f "www.drscheme.org" #f #f () ((bár . "é")) #f)) => #("http" #f "www.drscheme.org" #f #f () ((bár . "é")) #f))