Further explain silent acceptance of unencoded characters.

Also highlight the two tests that use that.
This commit is contained in:
Eli Barzilay 2013-07-05 20:20:43 -04:00
parent 91c43fed9d
commit 8d55b892ec
2 changed files with 11 additions and 5 deletions

View File

@ -44,7 +44,7 @@
=> (->vec expected)))
(provide tests)
(module+ main (tests))
(module+ main (test do (tests)))
(define (tests)
(test
;; 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)
"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=馨慧")
#("http" #f "www.drscheme.org" #f #f () ((bar . "馨慧")) #f))
(test (string->url/vec "http://www.drscheme.org?bár=é")
=> #("http" #f "www.drscheme.org" #f #f () ((bár . "é")) #f))

View File

@ -177,9 +177,12 @@ See more in PR8831.
(cond [hex (cons hex rest)]
[(char<? c max-ascii) (cons (vector-ref table (char->integer c))
rest)]
;; 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
;; 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; 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)))
(internal-decode l))]))))
(bytes->string/utf-8 (apply bytes (internal-decode (string->list str)))))