Skip to content

Commit 8357ebf

Browse files
Renegade334aduh95
authored andcommitted
url: suppress warnings from url.format/url.resolve inside node_modules
PR-URL: #62005 Fixes: #61724 Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent d8ea1aa commit 8357ebf

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

lib/url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const {
131131
let urlParseWarned = false;
132132

133133
function urlParse(url, parseQueryString, slashesDenoteHost) {
134-
if (!urlParseWarned && !isInsideNodeModules(2)) {
134+
if (!urlParseWarned && !isInsideNodeModules(4)) {
135135
urlParseWarned = true;
136136
process.emitWarning(
137137
'`url.parse()` behavior is not standardized and prone to ' +

test/fixtures/node_modules/url-deprecations.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fixtures = require('../common/fixtures');
5+
6+
const assert = require('assert');
7+
const url = require('url');
8+
9+
const fixturePath = fixtures.path('node_modules', 'url-deprecations.js');
10+
11+
// Application deprecation for url.parse()
12+
url.parse('foo');
13+
common.expectWarning('DeprecationWarning',
14+
[/`url\.parse\(\)` behavior is not standardized/, 'DEP0169']);
15+
16+
// No warnings from inside node_modules
17+
common.spawnPromisified(process.execPath, [fixturePath]).then(
18+
common.mustCall(({ code, signal, stderr }) => {
19+
assert.strictEqual(code, 0);
20+
assert.strictEqual(signal, null);
21+
assert.doesNotMatch(stderr, /\[DEP0169\]/);
22+
})
23+
);

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,6 @@ if (common.hasIntl) {
8989
}));
9090
});
9191

92-
// Warning should only happen once per process.
93-
common.expectWarning({
94-
DeprecationWarning: {
95-
// eslint-disable-next-line @stylistic/js/max-len
96-
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.',
97-
DEP0170: `The URL ${badURLs[0]} is invalid. Future versions of Node.js will throw an error.`,
98-
},
99-
});
10092
badURLs.forEach((badURL) => {
10193
url.parse(badURL);
10294
});

0 commit comments

Comments
 (0)