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‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,11 +1308,17 @@ function originFor(url, base){
13081308
}
13091309

13101310
functiondomainToASCII(domain){
1311+
if(arguments.length<1)
1312+
thrownewTypeError('"domain" argument must be specified');
1313+
13111314
// toUSVString is not needed.
13121315
returnbinding.domainToASCII(`${domain}`);
13131316
}
13141317

13151318
functiondomainToUnicode(domain){
1319+
if(arguments.length<1)
1320+
thrownewTypeError('"domain" argument must be specified');
1321+
13161322
// toUSVString is not needed.
13171323
returnbinding.domainToUnicode(`${domain}`);
13181324
}

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

Lines changed: 9 additions & 0 deletions
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
consttests=require('../fixtures/url-idna.js');
1414

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

0 commit comments

Comments
(0)