url: suppress warnings from url.format/url.resolve inside node_modules

PR-URL: https://github.com/nodejs/node/pull/62005
Fixes: https://github.com/nodejs/node/issues/61724
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
René authored and GitHub committed 2026-03-08 18:32:29 +00:00
1 parent 84ae06e411
commit 724ef8ef9e
4 files changed
+29 -8

No files matched your search

+1 -1
View File
@@ -132,7 +132,7 @@ const {
let urlParseWarned = false;
function urlParse(url, parseQueryString, slashesDenoteHost) {
if (!urlParseWarned && !isInsideNodeModules(2)) {
if (!urlParseWarned && !isInsideNodeModules(4)) {
urlParseWarned = true;
process.emitWarning(
'`url.parse()` behavior is not standardized and prone to ' +
+5
View File
@@ -0,0 +1,5 @@
const url = require('url');
url.parse('foo');
url.format('foo');
url.resolve('foo', 'bar');
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const url = require('url');
const fixturePath = fixtures.path('node_modules', 'url-deprecations.js');
// Application deprecation for url.parse()
url.parse('foo');
common.expectWarning('DeprecationWarning',
[/`url\.parse\(\)` behavior is not standardized/, 'DEP0169']);
// No warnings from inside node_modules
common.spawnPromisified(process.execPath, [fixturePath]).then(
common.mustCall(({ code, signal, stderr }) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.doesNotMatch(stderr, /\[DEP0169\]/);
})
);
@@ -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',