Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: add pending-deprecation to url.parse() #47203

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3288,14 +3288,17 @@ Node-API callbacks.

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/47203
description: Added support for `--pending-deprecation`.
- version:
- v19.0.0
- v18.13.0
pr-url: https://github.com/nodejs/node/pull/44919
description: Documentation-only deprecation.
-->

Type: Documentation-only
Type: Documentation-only (supports [`--pending-deprecation`][])

[`url.parse()`][] behavior is not standardized and prone to errors that
have security implications. Use the [WHATWG URL API][] instead. CVEs are not
Expand Down
15 changes: 15 additions & 0 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const {
formatUrl,
} = internalBinding('url');

const { getOptionValue } = require('internal/options');

// Original url.parse() API

function Url() {
Expand Down Expand Up @@ -146,7 +148,20 @@ const {
CHAR_COLON,
} = require('internal/constants');

let urlParseWarned = false;

function urlParse(url, parseQueryString, slashesDenoteHost) {
if (!urlParseWarned && getOptionValue('--pending-deprecation')) {
urlParseWarned = true;
process.emitWarning(
anonrig marked this conversation as resolved.
Show resolved Hide resolved
'`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.',
'DeprecationWarning',
'DEP0169',
);
}

if (url instanceof Url) return url;

const urlObject = new Url();
Expand Down