summaryrefslogtreecommitdiff
path: root/lib/url.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2016-05-31 11:52:19 -0700
committerJames M Snell <jasnell@gmail.com>2016-10-11 12:41:42 -0700
commit4b312387ead4ba11146b28b8ac05ed385919c4af (patch)
treefd73b23a01d77c7024dc90402f1ec9cd9d2d479f /lib/url.js
parent88323e874473d18cce22d6ae134a056919c457e4 (diff)
downloadandroid-node-v8-4b312387ead4ba11146b28b8ac05ed385919c4af.tar.gz
android-node-v8-4b312387ead4ba11146b28b8ac05ed385919c4af.tar.bz2
android-node-v8-4b312387ead4ba11146b28b8ac05ed385919c4af.zip
url: adding WHATWG URL support
Implements WHATWG URL support. Example: ``` var u = new url.URL('http://example.org'); ``` Currently passing all WHATWG url parsing tests and all but two of the setter tests. The two setter tests are intentionally skipped for now but will be revisited. PR-URL: https://github.com/nodejs/node/pull/7448 Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Diffstat (limited to 'lib/url.js')
-rw-r--r--lib/url.js70
1 files changed, 4 insertions, 66 deletions
diff --git a/lib/url.js b/lib/url.js
index d935726872..201ebfedcc 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -10,10 +10,14 @@ function importPunycode() {
const { toASCII } = importPunycode();
+const internalUrl = require('internal/url');
+const encodeAuth = internalUrl.encodeAuth;
exports.parse = urlParse;
exports.resolve = urlResolve;
exports.resolveObject = urlResolveObject;
exports.format = urlFormat;
+exports.URL = internalUrl.URL;
+
exports.Url = Url;
@@ -942,69 +946,3 @@ function spliceOne(list, index) {
list[i] = list[k];
list.pop();
}
-
-var hexTable = new Array(256);
-for (var i = 0; i < 256; ++i)
- hexTable[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase();
-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);
-
- // These characters do not need escaping:
- // ! - . _ ~
- // ' ( ) * :
- // digits
- // alpha (uppercase)
- // alpha (lowercase)
- if (c === 0x21 || c === 0x2D || c === 0x2E || c === 0x5F || c === 0x7E ||
- (c >= 0x27 && c <= 0x2A) ||
- (c >= 0x30 && c <= 0x3A) ||
- (c >= 0x41 && c <= 0x5A) ||
- (c >= 0x61 && c <= 0x7A)) {
- continue;
- }
-
- if (i - lastPos > 0)
- out += str.slice(lastPos, i);
-
- lastPos = i + 1;
-
- // Other ASCII characters
- if (c < 0x80) {
- out += hexTable[c];
- continue;
- }
-
- // Multi-byte characters ...
- if (c < 0x800) {
- out += hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)];
- continue;
- }
- if (c < 0xD800 || c >= 0xE000) {
- 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;
- 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;
-}