From b9b93f2165bb94398b1fffb4f98066935c24e395 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Mon, 20 Mar 2017 14:29:54 -0700 Subject: [PATCH] url: error when domainTo*() is called w/o argument PR-URL: https://github.com/nodejs/node/pull/12507 Reviewed-By: James M Snell --- lib/internal/url.js | 6 ++++++ test/parallel/test-whatwg-url-domainto.js | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/internal/url.js b/lib/internal/url.js index 5fcabb803ef473..7fafc783dba4ae 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -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}`); } diff --git a/test/parallel/test-whatwg-url-domainto.js b/test/parallel/test-whatwg-url-domainto.js index f891f95a19cd3b..70b32c8dce279c 100644 --- a/test/parallel/test-whatwg-url-domainto.js +++ b/test/parallel/test-whatwg-url-domainto.js @@ -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),