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:
Timothy Gu authored and James M Snell committed 2017-04-04 09:51:44 -07:00
1 parent f6ddbaff8a
commit c4469c49ec
2 files changed
+15

No files matched your search

+6
View File
@@ -1308,11 +1308,17 @@ function originFor(url, base) {
}
function domainToASCII(domain) {
if (arguments.length < 1)
throw new TypeError('"domain" argument must be specified');
// toUSVString is not needed.
return binding.domainToASCII(`${domain}`);
}
function domainToUnicode(domain) {
if (arguments.length < 1)
throw new TypeError('"domain" argument must be specified');
// toUSVString is not needed.
return binding.domainToUnicode(`${domain}`);
}
@@ -12,6 +12,15 @@ const { domainToASCII, domainToUnicode } = require('url');
// Tests below are not from WPT.
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()) {
assert.strictEqual(ascii, domainToASCII(unicode),