Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 24c2249

Browse filesBrowse files
simon-idaduh95
authored andcommitted
url: add type checking to urlToHttpOptions()
PR-URL: #59753 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Bryan English <bryan@bryanenglish.com>
1 parent 9833dc6 commit 24c2249
Copy full SHA for 24c2249

File tree

Expand file treeCollapse file tree

2 files changed

+12
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ const { Buffer } = require('buffer');
9090

9191
const {
9292
validateFunction,
93+
validateObject,
94+
kValidateObjectAllowObjects,
9395
} = require('internal/validators');
9496

9597
const { percentDecode } = require('internal/data_url');
@@ -1430,6 +1432,7 @@ function domainToUnicode(domain) {
14301432
* @returns {Record<string, unknown>}
14311433
*/
14321434
function urlToHttpOptions(url) {
1435+
validateObject(url, 'url', kValidateObjectAllowObjects);
14331436
const { hostname, pathname, port, username, password, search } = url;
14341437
const options = {
14351438
__proto__: null,
Collapse file

‎test/parallel/test-url-urltooptions.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-url-urltooptions.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ assert.strictEqual(copiedOpts.pathname, undefined);
3535
assert.strictEqual(copiedOpts.search, undefined);
3636
assert.strictEqual(copiedOpts.hash, undefined);
3737
assert.strictEqual(copiedOpts.href, undefined);
38+
39+
// Test when passed an invalid argument
40+
assert.throws(() => {
41+
urlToHttpOptions('http://127.0.0.1');
42+
}, {
43+
code: 'ERR_INVALID_ARG_TYPE',
44+
message: 'The "url" argument must be of type object. Received type string (\'http://127.0.0.1\')',
45+
name: 'TypeError'
46+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.