Skip to content

Commit 11fbdd8

Browse files
authored
url: runtime deprecate url.parse
PR-URL: #55017 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent c124cfb commit 11fbdd8

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

doc/api/deprecations.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3453,6 +3453,10 @@ Node-API callbacks.
34533453

34543454
<!-- YAML
34553455
changes:
3456+
- version:
3457+
- REPLACEME
3458+
pr-url: https://github.com/nodejs/node/pull/55017
3459+
description: Application deprecation.
34563460
- version:
34573461
- v19.9.0
34583462
- v18.17.0
@@ -3465,7 +3469,7 @@ changes:
34653469
description: Documentation-only deprecation.
34663470
-->
34673471

3468-
Type: Documentation-only (supports [`--pending-deprecation`][])
3472+
Type: Application (non-`node_modules` code only)
34693473

34703474
[`url.parse()`][] behavior is not standardized and prone to errors that
34713475
have security implications. Use the [WHATWG URL API][] instead. CVEs are not

lib/url.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const {
4646
// This ensures setURLConstructor() is called before the native
4747
// URL::ToObject() method is used.
4848
const { spliceOne } = require('internal/util');
49+
const { isInsideNodeModules } = internalBinding('util');
4950

5051
// WHATWG URL implementation provided by internal/url
5152
const {
@@ -63,8 +64,6 @@ const {
6364

6465
const bindingUrl = internalBinding('url');
6566

66-
const { getOptionValue } = require('internal/options');
67-
6867
// Original url.parse() API
6968

7069
function Url() {
@@ -125,7 +124,7 @@ const {
125124
let urlParseWarned = false;
126125

127126
function urlParse(url, parseQueryString, slashesDenoteHost) {
128-
if (!urlParseWarned && getOptionValue('--pending-deprecation')) {
127+
if (!urlParseWarned && !isInsideNodeModules(100, true)) {
129128
urlParseWarned = true;
130129
process.emitWarning(
131130
'`url.parse()` behavior is not standardized and prone to ' +

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ if (common.hasIntl) {
9090
});
9191

9292
// Warning should only happen once per process.
93-
const expectedWarning = [
94-
`The URL ${badURLs[0]} is invalid. Future versions of Node.js will throw an error.`,
95-
'DEP0170',
96-
];
9793
common.expectWarning({
98-
DeprecationWarning: expectedWarning,
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+
},
9999
});
100100
badURLs.forEach((badURL) => {
101101
url.parse(badURL);

typings/internalBinding/util.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ export interface UtilBinding {
4545
guessHandleType(fd: number): 'TCP' | 'TTY' | 'UDP' | 'FILE' | 'PIPE' | 'UNKNOWN';
4646
parseEnv(content: string): Record<string, string>;
4747
styleText(format: Array<string> | string, text: string): string;
48+
isInsideNodeModules(frameLimit: number, defaultValue: unknown): boolean;
4849
}

0 commit comments

Comments
 (0)