summaryrefslogtreecommitdiff
path: root/lib/url.js
diff options
context:
space:
mode:
authorSergey Golovin <golovim@gmail.com>2018-03-01 22:18:37 +0300
committerAnna Henningsen <anna@addaleax.net>2018-03-23 13:01:47 +0100
commit38bae5dc23723b4f35a1569113caf2c76fb3195d (patch)
treeb63fcf43158a4eeba7c8492443cf48f79af45064 /lib/url.js
parentf32796fad2e77b789c0ad552dcddb891484e54fc (diff)
downloadandroid-node-v8-38bae5dc23723b4f35a1569113caf2c76fb3195d.tar.gz
android-node-v8-38bae5dc23723b4f35a1569113caf2c76fb3195d.tar.bz2
android-node-v8-38bae5dc23723b4f35a1569113caf2c76fb3195d.zip
url: remove redundant function
PR-URL: https://github.com/nodejs/node/pull/19076 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/url.js')
-rw-r--r--lib/url.js94
1 files changed, 20 insertions, 74 deletions
diff --git a/lib/url.js b/lib/url.js
index 61662b4a97..78c0ea3d17 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -38,7 +38,8 @@ const {
URLSearchParams,
domainToASCII,
domainToUnicode,
- formatSymbol
+ formatSymbol,
+ encodeStr,
} = require('internal/url');
// Original url.parse() API
@@ -543,10 +544,27 @@ function urlFormat(urlObject, options) {
return urlObject.format();
}
+// These characters do not need escaping:
+// ! - . _ ~
+// ' ( ) * :
+// digits
+// alpha (uppercase)
+// alpha (lowercase)
+const noEscapeAuth = [
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x00 - 0x0F
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x10 - 0x1F
+ 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 0x20 - 0x2F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 0x30 - 0x3F
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 - 0x4F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 0x50 - 0x5F
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 // 0x70 - 0x7F
+];
+
Url.prototype.format = function format() {
var auth = this.auth || '';
if (auth) {
- auth = encodeAuth(auth);
+ auth = encodeStr(auth, noEscapeAuth, hexTable);
auth += '@';
}
@@ -931,78 +949,6 @@ Url.prototype.parseHost = function parseHost() {
if (host) this.hostname = host;
};
-// These characters do not need escaping:
-// ! - . _ ~
-// ' ( ) * :
-// digits
-// alpha (uppercase)
-// alpha (lowercase)
-const noEscapeAuth = [
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x00 - 0x0F
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x10 - 0x1F
- 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 0x20 - 0x2F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 0x30 - 0x3F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 - 0x4F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 0x50 - 0x5F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 // 0x70 - 0x7F
-];
-
-function encodeAuth(str) {
- // faster encodeURIComponent alternative for encoding auth uri components
- var out = '';
- var lastPos = 0;
- for (var i = 0; i < str.length; ++i) {
- var c = str.charCodeAt(i);
-
- // ASCII
- if (c < 0x80) {
- if (noEscapeAuth[c] === 1)
- continue;
- if (lastPos < i)
- out += str.slice(lastPos, i);
- lastPos = i + 1;
- out += hexTable[c];
- continue;
- }
-
- if (lastPos < i)
- out += str.slice(lastPos, i);
-
- // Multi-byte characters ...
- if (c < 0x800) {
- lastPos = i + 1;
- out += hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)];
- continue;
- }
- if (c < 0xD800 || c >= 0xE000) {
- lastPos = i + 1;
- out += hexTable[0xE0 | (c >> 12)] +
- hexTable[0x80 | ((c >> 6) & 0x3F)] +
- hexTable[0x80 | (c & 0x3F)];
- continue;
- }
- // Surrogate pair
- ++i;
- var c2;
- if (i < str.length)
- c2 = str.charCodeAt(i) & 0x3FF;
- else
- c2 = 0;
- lastPos = i + 1;
- c = 0x10000 + (((c & 0x3FF) << 10) | c2);
- out += hexTable[0xF0 | (c >> 18)] +
- hexTable[0x80 | ((c >> 12) & 0x3F)] +
- hexTable[0x80 | ((c >> 6) & 0x3F)] +
- hexTable[0x80 | (c & 0x3F)];
- }
- if (lastPos === 0)
- return str;
- if (lastPos < str.length)
- return out + str.slice(lastPos);
- return out;
-}
-
module.exports = {
// Original API
Url,