Skip to content

Commit deead95

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

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

‎lib/url.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const {
132132
leturlParseWarned=false;
133133

134134
functionurlParse(url,parseQueryString,slashesDenoteHost){
135-
if(!urlParseWarned&&!isInsideNodeModules(2)){
135+
if(!urlParseWarned&&!isInsideNodeModules(4)){
136136
urlParseWarned=true;
137137
process.emitWarning(
138138
'`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+
constcommon=require('../common');
4+
constfixtures=require('../common/fixtures');
5+
6+
constassert=require('assert');
7+
consturl=require('url');
8+
9+
constfixturePath=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\(\)`behaviorisnotstandardized/,'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 & 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',

0 commit comments

Comments
 (0)