Skip to content

Commit b3a002e

Browse files
committed
Update percent-encoding internal function names
This matches the spec change at whatwg/url#243.
1 parent a273c96 commit b3a002e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/url-state-machine.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,24 @@ function utf8PercentDecode(str) {
121121
return new Buffer(output).toString();
122122
}
123123

124-
function isSimpleEncode(c) {
124+
function isC0ControlPercentEncode(c) {
125125
return c <= 0x1F || c > 0x7E;
126126
}
127127

128-
const defaultEncodeSet = new Set([p(" "), p("\""), p("#"), p("<"), p(">"), p("?"), p("`"), p("{"), p("}")]);
129-
function isDefaultEncode(c) {
130-
return isSimpleEncode(c) || defaultEncodeSet.has(c);
128+
const extraPathPercentEncodeSet = new Set([p(" "), p("\""), p("#"), p("<"), p(">"), p("?"), p("`"), p("{"), p("}")]);
129+
function isPathPercentEncode(c) {
130+
return isC0ControlPercentEncode(c) || extraPathPercentEncodeSet.has(c);
131131
}
132132

133-
const userInfoEncodeSet = new Set([p("/"), p(":"), p(";"), p("="), p("@"), p("["), p("\\"), p("]"), p("^"), p("|")]);
134-
function isUserInfoEncode(c) {
135-
return isDefaultEncode(c) || userInfoEncodeSet.has(c);
133+
const extraUserinfoPercentEncodeSet = new Set([p("/"), p(":"), p(";"), p("="), p("@"), p("["), p("\\"), p("]"), p("^"), p("|")]);
134+
function isUserinfoPercentEncode(c) {
135+
return isPathPercentEncode(c) || extraUserinfoPercentEncodeSet.has(c);
136136
}
137137

138-
function encodeChar(c, checkCb) {
138+
function percentEncodeChar(c, encodeSetPredicate) {
139139
const cStr = String.fromCodePoint(c);
140140

141-
if (checkCb(c)) {
141+
if (encodeSetPredicate(c)) {
142142
return utf8PercentEncode(cStr);
143143
}
144144

@@ -424,7 +424,7 @@ function parseOpaqueHost(input) {
424424
let output = "";
425425
const decoded = punycode.ucs2.decode(input);
426426
for (let i = 0; i < decoded.length; ++i) {
427-
output += encodeChar(decoded[i], isSimpleEncode);
427+
output += percentEncodeChar(decoded[i], isC0ControlPercentEncode);
428428
}
429429
return output;
430430
}
@@ -783,7 +783,7 @@ URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr)
783783
this.passwordTokenSeenFlag = true;
784784
continue;
785785
}
786-
const encodedCodePoints = encodeChar(codePoint, isUserInfoEncode);
786+
const encodedCodePoints = percentEncodeChar(codePoint, isUserinfoPercentEncode);
787787
if (this.passwordTokenSeenFlag) {
788788
this.url.password += encodedCodePoints;
789789
} else {
@@ -1064,7 +1064,7 @@ URLStateMachine.prototype["parse path"] = function parsePath(c) {
10641064
this.parseError = true;
10651065
}
10661066

1067-
this.buffer += encodeChar(c, isDefaultEncode);
1067+
this.buffer += percentEncodeChar(c, isPathPercentEncode);
10681068
}
10691069

10701070
return true;
@@ -1090,7 +1090,7 @@ URLStateMachine.prototype["parse cannot-be-a-base-URL path"] = function parseCan
10901090
}
10911091

10921092
if (!isNaN(c)) {
1093-
this.url.path[0] = this.url.path[0] + encodeChar(c, isSimpleEncode);
1093+
this.url.path[0] = this.url.path[0] + percentEncodeChar(c, isC0ControlPercentEncode);
10941094
}
10951095
}
10961096

@@ -1144,7 +1144,7 @@ URLStateMachine.prototype["parse fragment"] = function parseFragment(c) {
11441144
this.parseError = true;
11451145
}
11461146

1147-
this.url.fragment += encodeChar(c, isSimpleEncode);
1147+
this.url.fragment += percentEncodeChar(c, isC0ControlPercentEncode);
11481148
}
11491149

11501150
return true;
@@ -1254,15 +1254,15 @@ module.exports.setTheUsername = function (url, username) {
12541254
url.username = "";
12551255
const decoded = punycode.ucs2.decode(username);
12561256
for (let i = 0; i < decoded.length; ++i) {
1257-
url.username += encodeChar(decoded[i], isUserInfoEncode);
1257+
url.username += percentEncodeChar(decoded[i], isUserinfoPercentEncode);
12581258
}
12591259
};
12601260

12611261
module.exports.setThePassword = function (url, password) {
12621262
url.password = "";
12631263
const decoded = punycode.ucs2.decode(password);
12641264
for (let i = 0; i < decoded.length; ++i) {
1265-
url.password += encodeChar(decoded[i], isUserInfoEncode);
1265+
url.password += percentEncodeChar(decoded[i], isUserinfoPercentEncode);
12661266
}
12671267
};
12681268

0 commit comments

Comments
 (0)