Skip to content

Commit 3f93972

Browse files
committed
url: only emit DEP0169 on url.parse
1 parent 6682787 commit 3f93972

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

lib/url.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
143143
);
144144
}
145145

146+
return internalUrlParse(url, parseQueryString, slashesDenoteHost);
147+
}
148+
149+
function internalUrlParse(url, parseQueryString, slashesDenoteHost) {
146150
if (url instanceof Url) return url;
147151

148152
const urlObject = new Url();
@@ -578,7 +582,7 @@ function urlFormat(urlObject, options) {
578582
// this way, you can call urlParse() on strings
579583
// to clean up potentially wonky urls.
580584
if (typeof urlObject === 'string') {
581-
urlObject = urlParse(urlObject);
585+
urlObject = internalUrlParse(urlObject);
582586
} else if (typeof urlObject !== 'object' || urlObject === null) {
583587
throw new ERR_INVALID_ARG_TYPE('urlObject',
584588
['Object', 'string'], urlObject);
@@ -718,16 +722,16 @@ Url.prototype.format = function format() {
718722
};
719723

720724
function urlResolve(source, relative) {
721-
return urlParse(source, false, true).resolve(relative);
725+
return internalUrlParse(source, false, true).resolve(relative);
722726
}
723727

724728
Url.prototype.resolve = function resolve(relative) {
725-
return this.resolveObject(urlParse(relative, false, true)).format();
729+
return this.resolveObject(internalUrlParse(relative, false, true)).format();
726730
};
727731

728732
function urlResolveObject(source, relative) {
729733
if (!source) return relative;
730-
return urlParse(source, false, true).resolveObject(relative);
734+
return internalUrlParse(source, false, true).resolveObject(relative);
731735
}
732736

733737
Url.prototype.resolveObject = function resolveObject(relative) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const url = require('node:url');
5+
6+
// Warning should only happen once per process.
7+
common.expectWarning({
8+
DeprecationWarning: {
9+
// eslint-disable-next-line @stylistic/js/max-len
10+
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.',
11+
},
12+
});
13+
url.parse('https://nodejs.org');

test/parallel/test-url-parse-invalid-input.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ if (common.hasIntl) {
8787
}));
8888
});
8989

90-
// Warning should only happen once per process.
91-
common.expectWarning({
92-
DeprecationWarning: {
93-
// eslint-disable-next-line @stylistic/js/max-len
94-
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.',
95-
},
96-
});
9790
badURLs.forEach((badURL) => {
9891
assert.throws(() => url.parse(badURL), {
9992
code: 'ERR_INVALID_ARG_VALUE',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const url = require('node:url');
5+
6+
process.on('warning', common.mustNotCall());
7+
8+
// Both `url.resolve` and `url.format` should not trigger warnings even if
9+
// they internally depend on `url.parse`.
10+
url.resolve('https://nodejs.org', '/dist');
11+
url.format({
12+
protocol: 'https',
13+
hostname: 'nodejs.org',
14+
pathname: '/some/path',
15+
query: {
16+
page: 1,
17+
format: 'json',
18+
},
19+
});

0 commit comments

Comments
 (0)