url: move originFor, domainToAscii and domainToUnicode
Move non-standard methods to `url` module instead of exposing as static methods on the `URL` object. PR-URL: https://github.com/nodejs/node/pull/10512 Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
2213f3640a
commit
abc1633de6
@ -69,7 +69,7 @@ class TupleOrigin {
|
|||||||
toString(unicode = false) {
|
toString(unicode = false) {
|
||||||
var result = this[kScheme];
|
var result = this[kScheme];
|
||||||
result += '://';
|
result += '://';
|
||||||
result += unicode ? URL.domainToUnicode(this[kHost]) : this[kHost];
|
result += unicode ? domainToUnicode(this[kHost]) : this[kHost];
|
||||||
if (this[kPort] !== undefined && this[kPort] !== null)
|
if (this[kPort] !== undefined && this[kPort] !== null)
|
||||||
result += `:${this[kPort]}`;
|
result += `:${this[kPort]}`;
|
||||||
return result;
|
return result;
|
||||||
@ -898,13 +898,16 @@ function originFor(url, base) {
|
|||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
URL.originFor = originFor;
|
function domainToASCII(domain) {
|
||||||
URL.domainToASCII = function(domain) {
|
|
||||||
return binding.domainToASCII(String(domain));
|
return binding.domainToASCII(String(domain));
|
||||||
};
|
}
|
||||||
URL.domainToUnicode = function(domain) {
|
|
||||||
|
function domainToUnicode(domain) {
|
||||||
return binding.domainToUnicode(String(domain));
|
return binding.domainToUnicode(String(domain));
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.URL = URL;
|
exports.URL = URL;
|
||||||
|
exports.originFor = originFor;
|
||||||
|
exports.domainToASCII = domainToASCII;
|
||||||
|
exports.domainToUnicode = domainToUnicode;
|
||||||
exports.encodeAuth = encodeAuth;
|
exports.encodeAuth = encodeAuth;
|
||||||
|
@ -17,6 +17,9 @@ exports.resolve = urlResolve;
|
|||||||
exports.resolveObject = urlResolveObject;
|
exports.resolveObject = urlResolveObject;
|
||||||
exports.format = urlFormat;
|
exports.format = urlFormat;
|
||||||
exports.URL = internalUrl.URL;
|
exports.URL = internalUrl.URL;
|
||||||
|
exports.originFor = internalUrl.originFor;
|
||||||
|
exports.domainToASCII = internalUrl.domainToASCII;
|
||||||
|
exports.domainToUnicode = internalUrl.domainToUnicode;
|
||||||
|
|
||||||
|
|
||||||
exports.Url = Url;
|
exports.Url = Url;
|
||||||
|
@ -4,8 +4,8 @@ require('../common');
|
|||||||
const strictEqual = require('assert').strictEqual;
|
const strictEqual = require('assert').strictEqual;
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
|
||||||
const domainToASCII = url.URL.domainToASCII;
|
const domainToASCII = url.domainToASCII;
|
||||||
const domainToUnicode = url.URL.domainToUnicode;
|
const domainToUnicode = url.domainToUnicode;
|
||||||
|
|
||||||
const domainWithASCII = [
|
const domainWithASCII = [
|
||||||
['ıídيٴ', 'xn--d-iga7ro0q9f'],
|
['ıídيٴ', 'xn--d-iga7ro0q9f'],
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
require('../common');
|
require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const inspect = require('util').inspect;
|
const inspect = require('util').inspect;
|
||||||
const URL = require('url').URL;
|
const originFor = require('url').originFor;
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
inspect(URL.originFor('http://test.com:8000')),
|
inspect(originFor('http://test.com:8000')),
|
||||||
`TupleOrigin {
|
`TupleOrigin {
|
||||||
scheme: http,
|
scheme: http,
|
||||||
host: test.com,
|
host: test.com,
|
||||||
@ -16,7 +16,7 @@ assert.strictEqual(
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
inspect(URL.originFor('http://test.com')),
|
inspect(originFor('http://test.com')),
|
||||||
`TupleOrigin {
|
`TupleOrigin {
|
||||||
scheme: http,
|
scheme: http,
|
||||||
host: test.com,
|
host: test.com,
|
||||||
@ -27,7 +27,7 @@ assert.strictEqual(
|
|||||||
|
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
inspect(URL.originFor('https://test.com')),
|
inspect(originFor('https://test.com')),
|
||||||
`TupleOrigin {
|
`TupleOrigin {
|
||||||
scheme: https,
|
scheme: https,
|
||||||
host: test.com,
|
host: test.com,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
const URL = require('url').URL;
|
const originFor = require('url').originFor;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const tests = require(path.join(common.fixturesDir, 'url-tests.json'));
|
const tests = require(path.join(common.fixturesDir, 'url-tests.json'));
|
||||||
@ -12,7 +12,7 @@ for (const test of tests) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (test.origin) {
|
if (test.origin) {
|
||||||
const origin = URL.originFor(test.input, test.base);
|
const origin = originFor(test.input, test.base);
|
||||||
// Pass true to origin.toString() to enable unicode serialization.
|
// Pass true to origin.toString() to enable unicode serialization.
|
||||||
assert.strictEqual(origin.toString(true), test.origin);
|
assert.strictEqual(origin.toString(true), test.origin);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user