Skip to content

Commit

Permalink
url: runtime deprecate url.parse
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Oct 18, 2024
1 parent 291d90a commit 7edf095
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 5 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3441,6 +3441,10 @@ Node-API callbacks.

<!-- YAML
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/55017
description: Application deprecation.
- version:
- v19.9.0
- v18.17.0
Expand All @@ -3453,7 +3457,7 @@ changes:
description: Documentation-only deprecation.
-->

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

[`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
6 changes: 2 additions & 4 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const {

// This ensures setURLConstructor() is called before the native
// URL::ToObject() method is used.
const { spliceOne } = require('internal/util');
const { isInsideNodeModules, spliceOne } = require('internal/util');

// WHATWG URL implementation provided by internal/url
const {
Expand All @@ -63,8 +63,6 @@ const {

const bindingUrl = internalBinding('url');

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

// Original url.parse() API

function Url() {
Expand Down Expand Up @@ -125,7 +123,7 @@ const {
let urlParseWarned = false;

function urlParse(url, parseQueryString, slashesDenoteHost) {
if (!urlParseWarned && getOptionValue('--pending-deprecation')) {
if (!urlParseWarned && !isInsideNodeModules()) {
urlParseWarned = true;
process.emitWarning(
'`url.parse()` behavior is not standardized and prone to ' +
Expand Down

0 comments on commit 7edf095

Please sign in to comment.