url: error when domainTo*() is called w/o argument
PR-URL: https://github.com/nodejs/node/pull/12134 Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
f6ddbaff8a
commit
c4469c49ec
@ -1308,11 +1308,17 @@ function originFor(url, base) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function domainToASCII(domain) {
|
function domainToASCII(domain) {
|
||||||
|
if (arguments.length < 1)
|
||||||
|
throw new TypeError('"domain" argument must be specified');
|
||||||
|
|
||||||
// toUSVString is not needed.
|
// toUSVString is not needed.
|
||||||
return binding.domainToASCII(`${domain}`);
|
return binding.domainToASCII(`${domain}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function domainToUnicode(domain) {
|
function domainToUnicode(domain) {
|
||||||
|
if (arguments.length < 1)
|
||||||
|
throw new TypeError('"domain" argument must be specified');
|
||||||
|
|
||||||
// toUSVString is not needed.
|
// toUSVString is not needed.
|
||||||
return binding.domainToUnicode(`${domain}`);
|
return binding.domainToUnicode(`${domain}`);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,15 @@ const { domainToASCII, domainToUnicode } = require('url');
|
|||||||
// Tests below are not from WPT.
|
// Tests below are not from WPT.
|
||||||
const tests = require('../fixtures/url-idna.js');
|
const tests = require('../fixtures/url-idna.js');
|
||||||
|
|
||||||
|
{
|
||||||
|
assert.throws(() => domainToASCII(),
|
||||||
|
/^TypeError: "domain" argument must be specified$/);
|
||||||
|
assert.throws(() => domainToUnicode(),
|
||||||
|
/^TypeError: "domain" argument must be specified$/);
|
||||||
|
assert.strictEqual(domainToASCII(undefined), 'undefined');
|
||||||
|
assert.strictEqual(domainToUnicode(undefined), 'undefined');
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
for (const [i, { ascii, unicode }] of tests.valid.entries()) {
|
for (const [i, { ascii, unicode }] of tests.valid.entries()) {
|
||||||
assert.strictEqual(ascii, domainToASCII(unicode),
|
assert.strictEqual(ascii, domainToASCII(unicode),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user