Skip to content

Commit

Permalink
fix: handle url search params encoding correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Apr 11, 2024
1 parent c5c6575 commit ee9096a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/ada/character_sets-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,23 +462,23 @@ constexpr uint8_t WWW_FORM_URLENCODED_PERCENT_ENCODE[32] = {
// 30 31 32 33 34 35 36 37
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
// 38 39 3A 3B 3C 3D 3E 3F
0x00 | 0x00 | 0x00 | 0x00 | 0x10 | 0x00 | 0x40 | 0x80,
0x00 | 0x00 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
// 40 41 42 43 44 45 46 47
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
0x01 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
// 48 49 4A 4B 4C 4D 4E 4F
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
// 50 51 52 53 54 55 56 57
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
// 58 59 5A 5B 5C 5D 5E 5F
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
0x00 | 0x00 | 0x00 | 0x08 | 0x00 | 0x20 | 0x40 | 0x00,
// 60 61 62 63 64 65 66 67
0x01 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
// 68 69 6A 6B 6C 6D 6E 6F
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
// 70 71 72 73 74 75 76 77
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
// 78 79 7A 7B 7C 7D 7E 7F
0x00 | 0x00 | 0x00 | 0x08 | 0x00 | 0x20 | 0x40 | 0x80,
0x00 | 0x00 | 0x00 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
// 80 81 82 83 84 85 86 87
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
// 88 89 8A 8B 8C 8D 8E 8F
Expand Down
22 changes: 22 additions & 0 deletions tests/url_search_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,25 @@ TEST(url_search_params, test_to_string_encoding) {
"q1=foo&q2=foo+bar&q3=foo+bar&q4=foo%2Fbar");
SUCCEED();
}

// https://github.com/cloudflare/workerd/issues/1777
TEST(url_search_params, test_character_set) {
auto search_params = ada::url_search_params("key=value");

// - The application/x-www-form-urlencoded percent-encode set is the component
// percent-encode set and U+0021 (!), U+0027 (') to U+0029 RIGHT PARENTHESIS,
// inclusive, and U+007E (~).
// - The component percent-encode set is the userinfo percent-encode set and
// U+0024 ($) to U+0026 (&), inclusive, U+002B (+), and U+002C (,).
// - The userinfo percent-encode set is the path percent-encode set and U+002F
// (/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@), U+005B ([) to U+005E
// (^), inclusive, and U+007C (|).
std::vector<char> unique_keys = {'/', ':', ';', '=', '@', '[', ']', '^', '|',
'$', '&', '+', ',', '!', '\'', ')', '~'};
for (auto& unique_key : unique_keys) {
auto value = "value" + std::string(1, unique_key);
search_params.set("key", value);
ASSERT_NE(search_params.to_string(), "key=" + value);
}
SUCCEED();
}

0 comments on commit ee9096a

Please sign in to comment.