Skip to content

Commit fdc51a1

Browse files
daynintargos
authored andcommitted
url: remove redundant function
PR-URL: #19076 Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 99e3c77 commit fdc51a1

File tree

2 files changed

+21
-76
lines changed

2 files changed

+21
-76
lines changed

lib/internal/url.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,7 @@ function serializeParams(array) {
878878

879879
const firstEncodedParam = encodeStr(array[0], noEscape, paramHexTable);
880880
const firstEncodedValue = encodeStr(array[1], noEscape, paramHexTable);
881-
let output =
882-
`${firstEncodedParam}=${firstEncodedValue}`;
881+
let output = `${firstEncodedParam}=${firstEncodedValue}`;
883882

884883
for (var i = 2; i < len; i += 2) {
885884
const encodedParam = encodeStr(array[i], noEscape, paramHexTable);

lib/url.js

+20-74
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const {
3636
URLSearchParams,
3737
domainToASCII,
3838
domainToUnicode,
39-
formatSymbol
39+
formatSymbol,
40+
encodeStr,
4041
} = require('internal/url');
4142

4243
// Original url.parse() API
@@ -541,10 +542,27 @@ function urlFormat(urlObject, options) {
541542
return urlObject.format();
542543
}
543544

545+
// These characters do not need escaping:
546+
// ! - . _ ~
547+
// ' ( ) * :
548+
// digits
549+
// alpha (uppercase)
550+
// alpha (lowercase)
551+
const noEscapeAuth = [
552+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x00 - 0x0F
553+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x10 - 0x1F
554+
0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 0x20 - 0x2F
555+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 0x30 - 0x3F
556+
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 - 0x4F
557+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 0x50 - 0x5F
558+
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6F
559+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 // 0x70 - 0x7F
560+
];
561+
544562
Url.prototype.format = function format() {
545563
var auth = this.auth || '';
546564
if (auth) {
547-
auth = encodeAuth(auth);
565+
auth = encodeStr(auth, noEscapeAuth, hexTable);
548566
auth += '@';
549567
}
550568

@@ -929,78 +947,6 @@ Url.prototype.parseHost = function parseHost() {
929947
if (host) this.hostname = host;
930948
};
931949

932-
// These characters do not need escaping:
933-
// ! - . _ ~
934-
// ' ( ) * :
935-
// digits
936-
// alpha (uppercase)
937-
// alpha (lowercase)
938-
const noEscapeAuth = [
939-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x00 - 0x0F
940-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x10 - 0x1F
941-
0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 0x20 - 0x2F
942-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 0x30 - 0x3F
943-
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 - 0x4F
944-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 0x50 - 0x5F
945-
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6F
946-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 // 0x70 - 0x7F
947-
];
948-
949-
function encodeAuth(str) {
950-
// faster encodeURIComponent alternative for encoding auth uri components
951-
var out = '';
952-
var lastPos = 0;
953-
for (var i = 0; i < str.length; ++i) {
954-
var c = str.charCodeAt(i);
955-
956-
// ASCII
957-
if (c < 0x80) {
958-
if (noEscapeAuth[c] === 1)
959-
continue;
960-
if (lastPos < i)
961-
out += str.slice(lastPos, i);
962-
lastPos = i + 1;
963-
out += hexTable[c];
964-
continue;
965-
}
966-
967-
if (lastPos < i)
968-
out += str.slice(lastPos, i);
969-
970-
// Multi-byte characters ...
971-
if (c < 0x800) {
972-
lastPos = i + 1;
973-
out += hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)];
974-
continue;
975-
}
976-
if (c < 0xD800 || c >= 0xE000) {
977-
lastPos = i + 1;
978-
out += hexTable[0xE0 | (c >> 12)] +
979-
hexTable[0x80 | ((c >> 6) & 0x3F)] +
980-
hexTable[0x80 | (c & 0x3F)];
981-
continue;
982-
}
983-
// Surrogate pair
984-
++i;
985-
var c2;
986-
if (i < str.length)
987-
c2 = str.charCodeAt(i) & 0x3FF;
988-
else
989-
c2 = 0;
990-
lastPos = i + 1;
991-
c = 0x10000 + (((c & 0x3FF) << 10) | c2);
992-
out += hexTable[0xF0 | (c >> 18)] +
993-
hexTable[0x80 | ((c >> 12) & 0x3F)] +
994-
hexTable[0x80 | ((c >> 6) & 0x3F)] +
995-
hexTable[0x80 | (c & 0x3F)];
996-
}
997-
if (lastPos === 0)
998-
return str;
999-
if (lastPos < str.length)
1000-
return out + str.slice(lastPos);
1001-
return out;
1002-
}
1003-
1004950
module.exports = {
1005951
// Original API
1006952
Url,

0 commit comments

Comments
 (0)