mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
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:
4 files changed
+29
-8
No files matched your search
+1
-1
@@ -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
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user