Skip to content

Commit 880f10c

Browse files
authored
fix: quotes need to be percent encoded in paths. (#242)
1 parent 99792aa commit 880f10c

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/checkers.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace ada::checkers {
1919
}
2020

2121

22-
// for use with path_signature
22+
// for use with path_signature, we include all characters that need percent encoding.
2323
static constexpr uint8_t path_signature_table[256] = {
2424
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
25-
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0,
25+
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0,
2626
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
2727
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
2828
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -32,8 +32,28 @@ namespace ada::checkers {
3232
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3333
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3434
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
35+
static_assert(path_signature_table[uint8_t('?')] == 1);
36+
static_assert(path_signature_table[uint8_t('`')] == 1);
37+
static_assert(path_signature_table[uint8_t('{')] == 1);
38+
static_assert(path_signature_table[uint8_t('}')] == 1);
39+
//
40+
static_assert(path_signature_table[uint8_t(' ')] == 1);
41+
static_assert(path_signature_table[uint8_t('?')] == 1);
42+
static_assert(path_signature_table[uint8_t('"')] == 1);
43+
static_assert(path_signature_table[uint8_t('#')] == 1);
44+
static_assert(path_signature_table[uint8_t('<')] == 1);
45+
static_assert(path_signature_table[uint8_t('>')] == 1);
46+
//
47+
static_assert(path_signature_table[0] == 1);
48+
static_assert(path_signature_table[31] == 1);
49+
static_assert(path_signature_table[127] == 1);
50+
static_assert(path_signature_table[128] == 1);
51+
static_assert(path_signature_table[255] == 1);
3552

3653
ada_really_inline constexpr uint8_t path_signature(std::string_view input) noexcept {
54+
// The path percent-encode set is the query percent-encode set and U+003F (?), U+0060 (`), U+007B ({), and U+007D (}).
55+
// The query percent-encode set is the C0 control percent-encode set and U+0020 SPACE, U+0022 ("), U+0023 (#), U+003C (<), and U+003E (>).
56+
// The C0 control percent-encode set are the C0 controls and all code points greater than U+007E (~).
3757
size_t i = 0;
3858
uint8_t accumulator{};
3959
for (; i + 7 < input.size(); i += 8) {

tests/wpt/ada_extra_urltestdata.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,20 @@
226226
"input": "",
227227
"base": "about:blank",
228228
"failure": true
229+
},
230+
{
231+
"input": "https://example.com/\"quoted\"",
232+
"base": "about:blank",
233+
"href": "https://example.com/%22quoted%22",
234+
"origin": "https://example.com",
235+
"protocol": "https:",
236+
"username": "",
237+
"password": "",
238+
"host": "example.com",
239+
"hostname": "example.com",
240+
"port": "",
241+
"pathname": "/%22quoted%22",
242+
"search": "",
243+
"hash": ""
229244
}
230245
]

0 commit comments

Comments
 (0)