Skip to content

Commit 7fb1980

Browse files
anonrigdanielleadams
authored andcommitted
url: add pending-deprecation to url.parse()
PR-URL: #47203 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 9cbf897 commit 7fb1980

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

doc/api/deprecations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3271,13 +3271,16 @@ Node-API callbacks.
32713271

32723272
<!-- YAML
32733273
changes:
3274+
- version: REPLACEME
3275+
pr-url: https://github.com/nodejs/node/pull/47203
3276+
description: Added support for `--pending-deprecation`.
32743277
- version:
32753278
- v18.13.0
32763279
pr-url: https://github.com/nodejs/node/pull/44919
32773280
description: Documentation-only deprecation.
32783281
-->
32793282

3280-
Type: Documentation-only
3283+
Type: Documentation-only (supports [`--pending-deprecation`][])
32813284

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

lib/url.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const {
6363
formatUrl,
6464
} = internalBinding('url');
6565

66+
const { getOptionValue } = require('internal/options');
67+
6668
// Original url.parse() API
6769

6870
function Url() {
@@ -147,7 +149,20 @@ const {
147149
CHAR_COLON,
148150
} = require('internal/constants');
149151

152+
let urlParseWarned = false;
153+
150154
function urlParse(url, parseQueryString, slashesDenoteHost) {
155+
if (!urlParseWarned && getOptionValue('--pending-deprecation')) {
156+
urlParseWarned = true;
157+
process.emitWarning(
158+
'`url.parse()` behavior is not standardized and prone to ' +
159+
'errors that have security implications. Use the WHATWG URL API ' +
160+
'instead. CVEs are not issued for `url.parse()` vulnerabilities.',
161+
'DeprecationWarning',
162+
'DEP0169',
163+
);
164+
}
165+
151166
if (url instanceof Url) return url;
152167

153168
const urlObject = new Url();

0 commit comments

Comments
 (0)