Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
);
}

return internalUrlParse(url, parseQueryString, slashesDenoteHost);
}

function internalUrlParse(url, parseQueryString, slashesDenoteHost) {
if (url instanceof Url) return url;

const urlObject = new Url();
Expand Down Expand Up @@ -578,7 +582,7 @@ function urlFormat(urlObject, options) {
// this way, you can call urlParse() on strings
// to clean up potentially wonky urls.
if (typeof urlObject === 'string') {
urlObject = urlParse(urlObject);
urlObject = internalUrlParse(urlObject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is already documented as application-deprecated.

} else if (typeof urlObject !== 'object' || urlObject === null) {
throw new ERR_INVALID_ARG_TYPE('urlObject',
['Object', 'string'], urlObject);
Expand Down Expand Up @@ -718,16 +722,16 @@ Url.prototype.format = function format() {
};

function urlResolve(source, relative) {
return urlParse(source, false, true).resolve(relative);
return internalUrlParse(source, false, true).resolve(relative);
}

Url.prototype.resolve = function resolve(relative) {
return this.resolveObject(urlParse(relative, false, true)).format();
return this.resolveObject(internalUrlParse(relative, false, true)).format();
};

function urlResolveObject(source, relative) {
if (!source) return relative;
return urlParse(source, false, true).resolveObject(relative);
return internalUrlParse(source, false, true).resolveObject(relative);
}

Url.prototype.resolveObject = function resolveObject(relative) {
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-url-parse-dep0169.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const common = require('../common');
const url = require('node:url');

// Warning should only happen once per process.
common.expectWarning({
DeprecationWarning: {
// eslint-disable-next-line @stylistic/js/max-len
DEP0169: '`url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.',
},
});
url.parse('https://nodejs.org');
7 changes: 0 additions & 7 deletions test/parallel/test-url-parse-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ if (common.hasIntl) {
}));
});

// Warning should only happen once per process.
common.expectWarning({
DeprecationWarning: {
// eslint-disable-next-line @stylistic/js/max-len
DEP0169: '`url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.',
},
});
badURLs.forEach((badURL) => {
assert.throws(() => url.parse(badURL), {
code: 'ERR_INVALID_ARG_VALUE',
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-url-parse-no-dep0169.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const common = require('../common');
const url = require('node:url');

process.on('warning', common.mustNotCall());

// Both `url.resolve` and `url.format` should not trigger warnings even if
// they internally depend on `url.parse`.
url.resolve('https://nodejs.org', '/dist');
url.format({
protocol: 'https',
hostname: 'nodejs.org',
pathname: '/some/path',
query: {
page: 1,
format: 'json',
},
});
Loading