From ec2acb8bc0610b88766c5ea4ef2b03fa8f08b9bb Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Fri, 5 Jul 2013 20:20:43 -0400 Subject: [PATCH] Further explain silent acceptance of unencoded characters. Also highlight the two tests that use that. (cherry picked from commit 8d55b892ecf871ea4d2e369afd98999b015b716b) --- collects/net/uri-codec.rkt | 9 ++++++--- collects/tests/net/url.rkt | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/collects/net/uri-codec.rkt b/collects/net/uri-codec.rkt index 69b8e311b7..6b8f5a0fd8 100644 --- a/collects/net/uri-codec.rkt +++ b/collects/net/uri-codec.rkt @@ -177,9 +177,12 @@ See more in PR8831. (cond [hex (cons hex rest)] [(charinteger 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))))) diff --git a/collects/tests/net/url.rkt b/collects/tests/net/url.rkt index cddf7685d1..33d2d82fc5 100644 --- a/collects/tests/net/url.rkt +++ b/collects/tests/net/url.rkt @@ -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))