Commit 18e3c9f1 authored by Kenton Varda's avatar Kenton Varda

The URI standard says to prefer upper-case hex for percent encoding.

parent 298db23e
......@@ -227,7 +227,7 @@ KJ_TEST("hex encoding/decoding") {
KJ_TEST("URI encoding/decoding") {
KJ_EXPECT(encodeUriComponent("foo") == "foo");
KJ_EXPECT(encodeUriComponent("foo bar") == "foo%20bar");
KJ_EXPECT(encodeUriComponent("\xab\xba") == "%ab%ba");
KJ_EXPECT(encodeUriComponent("\xab\xba") == "%AB%BA");
KJ_EXPECT(encodeUriComponent(StringPtr("foo\0bar", 7)) == "foo%00bar");
expectRes(decodeUriComponent("foo%20bar"), "foo bar");
......
......@@ -234,6 +234,11 @@ EncodingResult<String> decodeUtf32(ArrayPtr<const char32_t> utf16) {
namespace {
const char HEX_DIGITS[] = "0123456789abcdef";
// Maps integer in the range [0,16) to a hex digit.
const char HEX_DIGITS_URI[] = "0123456789ABCDEF";
// RFC 3986 section 2.1 says "For consistency, URI producers and normalizers should use uppercase
// hexadecimal digits for all percent-encodings.
static Maybe<uint> tryFromHexDigit(char c) {
if ('0' <= c && c <= '9') {
......@@ -294,8 +299,8 @@ String encodeUriComponent(ArrayPtr<const byte> bytes) {
result.add(b);
} else {
result.add('%');
result.add(HEX_DIGITS[b/16]);
result.add(HEX_DIGITS[b%16]);
result.add(HEX_DIGITS_URI[b/16]);
result.add(HEX_DIGITS_URI[b%16]);
}
}
result.add('\0');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment