Skip to content

Commit c207865

Browse files
TimothyGutargos
authored andcommitted
src: encode 0x27 (') for special URLs
Refs: whatwg/url@6ef17eb PR-URL: #22022 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent d86e615 commit c207865

File tree

2 files changed

+103
-3
lines changed

2 files changed

+103
-3
lines changed

src/node_url.cc

+71-2
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ const uint8_t USERINFO_ENCODE_SET[32] = {
529529
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80
530530
};
531531

532-
const uint8_t QUERY_ENCODE_SET[32] = {
532+
const uint8_t QUERY_ENCODE_SET_NONSPECIAL[32] = {
533533
// 00 01 02 03 04 05 06 07
534534
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
535535
// 08 09 0A 0B 0C 0D 0E 0F
@@ -596,6 +596,74 @@ const uint8_t QUERY_ENCODE_SET[32] = {
596596
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80
597597
};
598598

599+
// Same as QUERY_ENCODE_SET_NONSPECIAL, but with 0x27 (') encoded.
600+
const uint8_t QUERY_ENCODE_SET_SPECIAL[32] = {
601+
// 00 01 02 03 04 05 06 07
602+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
603+
// 08 09 0A 0B 0C 0D 0E 0F
604+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
605+
// 10 11 12 13 14 15 16 17
606+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
607+
// 18 19 1A 1B 1C 1D 1E 1F
608+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
609+
// 20 21 22 23 24 25 26 27
610+
0x01 | 0x00 | 0x04 | 0x08 | 0x00 | 0x00 | 0x00 | 0x80,
611+
// 28 29 2A 2B 2C 2D 2E 2F
612+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
613+
// 30 31 32 33 34 35 36 37
614+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
615+
// 38 39 3A 3B 3C 3D 3E 3F
616+
0x00 | 0x00 | 0x00 | 0x00 | 0x10 | 0x00 | 0x40 | 0x00,
617+
// 40 41 42 43 44 45 46 47
618+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
619+
// 48 49 4A 4B 4C 4D 4E 4F
620+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
621+
// 50 51 52 53 54 55 56 57
622+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
623+
// 58 59 5A 5B 5C 5D 5E 5F
624+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
625+
// 60 61 62 63 64 65 66 67
626+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
627+
// 68 69 6A 6B 6C 6D 6E 6F
628+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
629+
// 70 71 72 73 74 75 76 77
630+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
631+
// 78 79 7A 7B 7C 7D 7E 7F
632+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x80,
633+
// 80 81 82 83 84 85 86 87
634+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
635+
// 88 89 8A 8B 8C 8D 8E 8F
636+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
637+
// 90 91 92 93 94 95 96 97
638+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
639+
// 98 99 9A 9B 9C 9D 9E 9F
640+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
641+
// A0 A1 A2 A3 A4 A5 A6 A7
642+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
643+
// A8 A9 AA AB AC AD AE AF
644+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
645+
// B0 B1 B2 B3 B4 B5 B6 B7
646+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
647+
// B8 B9 BA BB BC BD BE BF
648+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
649+
// C0 C1 C2 C3 C4 C5 C6 C7
650+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
651+
// C8 C9 CA CB CC CD CE CF
652+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
653+
// D0 D1 D2 D3 D4 D5 D6 D7
654+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
655+
// D8 D9 DA DB DC DD DE DF
656+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
657+
// E0 E1 E2 E3 E4 E5 E6 E7
658+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
659+
// E8 E9 EA EB EC ED EE EF
660+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
661+
// F0 F1 F2 F3 F4 F5 F6 F7
662+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
663+
// F8 F9 FA FB FC FD FE FF
664+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80
665+
};
666+
599667
inline bool BitAt(const uint8_t a[], const uint8_t i) {
600668
return !!(a[i >> 3] & (1 << (i & 7)));
601669
}
@@ -1990,7 +2058,8 @@ void URL::Parse(const char* input,
19902058
if (ch == '#')
19912059
state = kFragment;
19922060
} else {
1993-
AppendOrEscape(&buffer, ch, QUERY_ENCODE_SET);
2061+
AppendOrEscape(&buffer, ch, special ? QUERY_ENCODE_SET_SPECIAL :
2062+
QUERY_ENCODE_SET_NONSPECIAL);
19942063
}
19952064
break;
19962065
case kFragment:

test/fixtures/url-tests.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* The following tests are copied from WPT. Modifications to them should be
44
upstreamed first. Refs:
5-
https://github.com/w3c/web-platform-tests/blob/88b75886e/url/urltestdata.json
5+
https://github.com/web-platform-tests/wpt/blob/ba4921d054/url/resources/urltestdata.json
66
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
77
*/
88
module.exports =
@@ -4023,6 +4023,37 @@ module.exports =
40234023
"search": "?`{}",
40244024
"hash": ""
40254025
},
4026+
"byte is ' and url is special",
4027+
{
4028+
"input": "http://host/?'",
4029+
"base": "about:blank",
4030+
"href": "http://host/?%27",
4031+
"origin": "http://host",
4032+
"protocol": "http:",
4033+
"username": "",
4034+
"password": "",
4035+
"host": "host",
4036+
"hostname": "host",
4037+
"port": "",
4038+
"pathname": "/",
4039+
"search": "?%27",
4040+
"hash": ""
4041+
},
4042+
{
4043+
"input": "notspecial://host/?'",
4044+
"base": "about:blank",
4045+
"href": "notspecial://host/?'",
4046+
"origin": "null",
4047+
"protocol": "notspecial:",
4048+
"username": "",
4049+
"password": "",
4050+
"host": "host",
4051+
"hostname": "host",
4052+
"port": "",
4053+
"pathname": "/",
4054+
"search": "?'",
4055+
"hash": ""
4056+
},
40264057
"# Credentials in base",
40274058
{
40284059
"input": "/some/path",

0 commit comments

Comments
 (0)