summaryrefslogtreecommitdiff
path: root/lib/internal/url.js
diff options
context:
space:
mode:
authorZYSzys <17367077526@163.com>2018-11-08 14:17:14 +0800
committerRich Trott <rtrott@gmail.com>2018-11-20 18:24:02 -0800
commitdb9a7459c3439c282ddcb7353e00491aeb704d22 (patch)
tree5742a9331a26afff8478db73d7e33570df9c0568 /lib/internal/url.js
parent399bb3c95af821350774c18f469ab700387f38e1 (diff)
downloadandroid-node-v8-db9a7459c3439c282ddcb7353e00491aeb704d22.tar.gz
android-node-v8-db9a7459c3439c282ddcb7353e00491aeb704d22.tar.bz2
android-node-v8-db9a7459c3439c282ddcb7353e00491aeb704d22.zip
lib: move encodeStr function to internal for reusable
PR-URL: https://github.com/nodejs/node/pull/24242 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/url.js')
-rw-r--r--lib/internal/url.js65
1 files changed, 1 insertions, 64 deletions
diff --git a/lib/internal/url.js b/lib/internal/url.js
index 693f082aed..44b658b2d9 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -2,6 +2,7 @@
const util = require('util');
const {
+ encodeStr,
hexTable,
isHexTable
} = require('internal/querystring');
@@ -833,70 +834,6 @@ const noEscape = [
const paramHexTable = hexTable.slice();
paramHexTable[0x20] = '+';
-function encodeStr(str, noEscapeTable, hexTable) {
- const len = str.length;
- if (len === 0)
- return '';
-
- var out = '';
- var lastPos = 0;
-
- for (var i = 0; i < len; i++) {
- var c = str.charCodeAt(i);
-
- // ASCII
- if (c < 0x80) {
- if (noEscapeTable[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 < len)
- c2 = str.charCodeAt(i) & 0x3FF;
- else {
- // This branch should never happen because all URLSearchParams entries
- // should already be converted to USVString. But, included for
- // completion's sake anyway.
- 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 < len)
- return out + str.slice(lastPos);
- return out;
-}
-
// application/x-www-form-urlencoded serializer
// Ref: https://url.spec.whatwg.org/#concept-urlencoded-serializer
function serializeParams(array) {