>From ae4fa3f65c1d49822b5a284a065017673c81e65e Mon Sep 17 00:00:00 2001 From: Ian Price Date: Mon, 20 Aug 2012 23:12:23 +0100 Subject: [PATCH 2/2] Fix uri-encoding for strings with no unreserved chars * 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 | 4 +++- test-suite/tests/web-uri.test | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/module/web/uri.scm b/module/web/uri.scm index 3816d02..78614a5 100644 --- a/module/web/uri.scm +++ b/module/web/uri.scm @@ -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 @address@hidden, 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 diff --git a/test-suite/tests/web-uri.test b/test-suite/tests/web-uri.test index a9ded46..3f6e7e3 100644 --- a/test-suite/tests/web-uri.test +++ b/test-suite/tests/web-uri.test @@ -259,4 +259,5 @@ (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 "<>\\^")))) -- 1.7.7.6