Skip to content

Commit 227e749

Browse files
KhafraDevtargos
authored andcommitted
url: validate URL constructor arg length
PR-URL: #47513 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent bf4ee17 commit 227e749

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

‎lib/internal/url.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ function isURL(self){
623623

624624
classURL{
625625
constructor(input,base=undefined){
626+
if(arguments.length===0){
627+
thrownewERR_MISSING_ARGS('url');
628+
}
629+
626630
// toUSVString is not needed.
627631
input=`${input}`;
628632
this[context]=newURLContext();
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
'use strict';
2-
3-
require('../common');
4-
constassert=require('assert');
5-
6-
// One argument is required
7-
assert.throws(()=>{
8-
URL.canParse();
9-
},{
10-
code: 'ERR_MISSING_ARGS',
11-
name: 'TypeError'
12-
});
1+
'use strict';
2+
3+
require('../common');
4+
constassert=require('assert');
5+
6+
// One argument is required
7+
assert.throws(()=>{
8+
URL.canParse();
9+
},{
10+
code: 'ERR_MISSING_ARGS',
11+
name: 'TypeError',
12+
});

‎test/parallel/test-whatwg-url-custom-parsing.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ for (const test of additional_tests){
7878
if(test.search)assert.strictEqual(url.search,test.search);
7979
if(test.hash)assert.strictEqual(url.hash,test.hash);
8080
}
81+
82+
assert.throws(()=>{
83+
newURL();
84+
},{
85+
name: 'TypeError',
86+
code: 'ERR_MISSING_ARGS',
87+
});

0 commit comments

Comments
(0)