From 30891b98e18526f5a2dd31350ac3fb86b0f60a7b Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 21 Mar 2023 15:38:12 -0400 Subject: [PATCH] url: add pending-deprecation to `url.parse()` --- doc/api/deprecations.md | 5 ++++- lib/url.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 95f53d05768589..f6272eef354976 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -3288,6 +3288,9 @@ Node-API callbacks. -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 diff --git a/lib/url.js b/lib/url.js index 45ecf043f95282..aa8094d36ec645 100644 --- a/lib/url.js +++ b/lib/url.js @@ -62,6 +62,8 @@ const { formatUrl, } = internalBinding('url'); +const { getOptionValue } = require('internal/options'); + // Original url.parse() API function Url() { @@ -147,6 +149,16 @@ const { } = require('internal/constants'); function urlParse(url, parseQueryString, slashesDenoteHost) { + if (getOptionValue('--pending-deprecation')){ + process.emitWarning( + '`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();