Skip to content

Commit

Permalink
url: error when domainTo*() is called w/o argument
Browse files Browse the repository at this point in the history
PR-URL: #12507
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
TimothyGu authored and evanlucas committed May 1, 2017
1 parent 1adb08e commit b9b93f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-whatwg-url-domainto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit b9b93f2

Please sign in to comment.