Fix uri-encoding for strings with no unreserved chars
authorIan Price <ianprice90@googlemail.com>
Mon, 20 Aug 2012 22:12:23 +0000 (23:12 +0100)
committerLudovic Courtès <ludo@gnu.org>
Sun, 26 Aug 2012 21:36:36 +0000 (23:36 +0200)
* module/web/uri.scm (uri-encode): Change test to check for unreserved
  chars instead of reserved chars.
* test-suite/tests/web-uri.test ("encode"): Add test.

module/web/uri.scm
test-suite/tests/web-uri.test

index 3816d02..78614a5 100644 (file)
@@ -364,7 +364,9 @@ Percent-encoding first writes out the given character to a bytevector
 within the given @var{encoding}, then encodes each byte as
 @code{%@var{HH}}, where @var{HH} is the hexadecimal representation of
 the byte."
-  (if (string-index str unescaped-chars)
+  (define (needs-escaped? ch)
+    (not (char-set-contains? unescaped-chars ch)))
+  (if (string-index str needs-escaped?)
       (call-with-output-string*
        (lambda (port)
          (string-for-each
index a9ded46..3f6e7e3 100644 (file)
 
 (with-test-prefix "encode"
   (pass-if (equal? "foo%20bar" (uri-encode "foo bar")))
-  (pass-if (equal? "foo%0a%00bar" (uri-encode "foo\n\x00bar"))))
+  (pass-if (equal? "foo%0a%00bar" (uri-encode "foo\n\x00bar")))
+  (pass-if (equal? "%3c%3e%5c%5e" (uri-encode "<>\\^"))))