Skip to content

Commit b9b93f2

Browse files
TimothyGuevanlucas
authored andcommitted
url: error when domainTo*() is called w/o argument
PR-URL: #12507 Reviewed-By: James M Snell <[email protected]>
1 parent 1adb08e commit b9b93f2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/internal/url.js

+6
Original file line numberDiff line numberDiff line change
@@ -1308,11 +1308,17 @@ function originFor(url, base) {
13081308
}
13091309

13101310
function domainToASCII(domain) {
1311+
if (arguments.length < 1)
1312+
throw new TypeError('"domain" argument must be specified');
1313+
13111314
// toUSVString is not needed.
13121315
return binding.domainToASCII(`${domain}`);
13131316
}
13141317

13151318
function domainToUnicode(domain) {
1319+
if (arguments.length < 1)
1320+
throw new TypeError('"domain" argument must be specified');
1321+
13161322
// toUSVString is not needed.
13171323
return binding.domainToUnicode(`${domain}`);
13181324
}

test/parallel/test-whatwg-url-domainto.js

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ const { domainToASCII, domainToUnicode } = require('url');
1212
// Tests below are not from WPT.
1313
const tests = require('../fixtures/url-idna.js');
1414

15+
{
16+
assert.throws(() => domainToASCII(),
17+
/^TypeError: "domain" argument must be specified$/);
18+
assert.throws(() => domainToUnicode(),
19+
/^TypeError: "domain" argument must be specified$/);
20+
assert.strictEqual(domainToASCII(undefined), 'undefined');
21+
assert.strictEqual(domainToUnicode(undefined), 'undefined');
22+
}
23+
1524
{
1625
for (const [i, { ascii, unicode }] of tests.valid.entries()) {
1726
assert.strictEqual(ascii, domainToASCII(unicode),

0 commit comments

Comments
 (0)