summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2016-12-31 14:20:10 +0800
committerJames M Snell <jasnell@gmail.com>2017-01-03 10:37:15 -0800
commit2177a381786465634ef095a20339a92ea96b91cc (patch)
tree2c1e4adf379dadd30a12a33c81c4ff3b8c00c26e
parentac90d298d4634b953c3e991fde93ab53f19b4d40 (diff)
downloadandroid-node-v8-2177a381786465634ef095a20339a92ea96b91cc.tar.gz
android-node-v8-2177a381786465634ef095a20339a92ea96b91cc.tar.bz2
android-node-v8-2177a381786465634ef095a20339a92ea96b91cc.zip
url: TupleOrigin#toString use unicode by default
See: https://url.spec.whatwg.org/#dom-url-origin Also moves the tests for origins to the parsing tests since now URL#origin matches the test cases by default. PR-URL: https://github.com/nodejs/node/pull/10552 Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--lib/internal/url.js5
-rw-r--r--test/parallel/test-whatwg-url-origin-for.js19
-rw-r--r--test/parallel/test-whatwg-url-parsing.js39
3 files changed, 25 insertions, 38 deletions
diff --git a/lib/internal/url.js b/lib/internal/url.js
index d7f859d95f..e7dabc4b9a 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -66,7 +66,8 @@ class TupleOrigin {
return this[kDomain] || this[kHost];
}
- toString(unicode = false) {
+ // https://url.spec.whatwg.org/#dom-url-origin
+ toString(unicode = true) {
var result = this[kScheme];
result += '://';
result += unicode ? domainToUnicode(this[kHost]) : this[kHost];
@@ -321,7 +322,7 @@ Object.defineProperties(URL.prototype, {
enumerable: true,
configurable: true,
get() {
- return originFor(this).toString(true);
+ return originFor(this).toString();
}
},
protocol: {
diff --git a/test/parallel/test-whatwg-url-origin-for.js b/test/parallel/test-whatwg-url-origin-for.js
deleted file mode 100644
index 9e015f8051..0000000000
--- a/test/parallel/test-whatwg-url-origin-for.js
+++ /dev/null
@@ -1,19 +0,0 @@
-'use strict';
-
-const common = require('../common');
-
-const originFor = require('url').originFor;
-const path = require('path');
-const assert = require('assert');
-const tests = require(path.join(common.fixturesDir, 'url-tests.json'));
-
-for (const test of tests) {
- if (typeof test === 'string')
- continue;
-
- if (test.origin) {
- const origin = originFor(test.input, test.base);
- // Pass true to origin.toString() to enable unicode serialization.
- assert.strictEqual(origin.toString(true), test.origin);
- }
-}
diff --git a/test/parallel/test-whatwg-url-parsing.js b/test/parallel/test-whatwg-url-parsing.js
index ae14d1ff50..c83d30da41 100644
--- a/test/parallel/test-whatwg-url-parsing.js
+++ b/test/parallel/test-whatwg-url-parsing.js
@@ -13,17 +13,30 @@ const path = require('path');
const assert = require('assert');
const tests = require(path.join(common.fixturesDir, 'url-tests.json'));
+function verifyURL(url, test) {
+ if (test.href) assert.strictEqual(url.href, test.href);
+ if (test.origin) assert.strictEqual(url.origin, test.origin);
+ if (test.protocol) assert.strictEqual(url.protocol, test.protocol);
+ if (test.username) assert.strictEqual(url.username, test.username);
+ if (test.password) assert.strictEqual(url.password, test.password);
+ if (test.hostname) assert.strictEqual(url.hostname, test.hostname);
+ if (test.host) assert.strictEqual(url.host, test.host);
+ if (test.port !== undefined) assert.strictEqual(url.port, test.port);
+ if (test.pathname) assert.strictEqual(url.pathname, test.pathname);
+ if (test.search) assert.strictEqual(url.search, test.search);
+ if (test.hash) assert.strictEqual(url.hash, test.hash);
+}
+
for (const test of tests) {
if (typeof test === 'string')
continue;
if (test.failure) {
- assert.throws(() => new URL(test.input, test.base), /Invalid URL/);
+ assert.throws(() => new URL(test.input, test.base),
+ /^TypeError: Invalid URL$/);
} else {
- assert.doesNotThrow(() => {
- const url = new URL(test.input, test.base);
- assert.strictEqual(url.href, test.href);
- });
+ const url = new URL(test.input, test.base);
+ verifyURL(url, test);
}
}
@@ -115,18 +128,10 @@ const additional_tests = [
}
];
-additional_tests.forEach((test) => {
- const u = new URL(test.url);
- if (test.protocol) assert.strictEqual(test.protocol, u.protocol);
- if (test.username) assert.strictEqual(test.username, u.username);
- if (test.password) assert.strictEqual(test.password, u.password);
- if (test.hostname) assert.strictEqual(test.hostname, u.hostname);
- if (test.host) assert.strictEqual(test.host, u.host);
- if (test.port !== undefined) assert.strictEqual(test.port, u.port);
- if (test.pathname) assert.strictEqual(test.pathname, u.pathname);
- if (test.search) assert.strictEqual(test.search, u.search);
- if (test.hash) assert.strictEqual(test.hash, u.hash);
-});
+for (const test of additional_tests) {
+ const url = new URL(test.url);
+ verifyURL(url, test);
+}
// test inspect
const allTests = additional_tests.slice();