lib: enforce use of URLParse

There's no reason to use the user-mutable `URL.parse` in  core.

PR-URL: https://github.com/nodejs/node/pull/61016
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Antoine du Hamel
2025-12-12 13:34:21 +01:00
committed by GitHub
parent 14f02fc2f7
commit 81e05e124f
3 changed files with 8 additions and 4 deletions

View File

@@ -30,6 +30,10 @@ const noRestrictedSyntax = [
selector: "CallExpression[callee.object.name='Error'][callee.property.name='captureStackTrace']", selector: "CallExpression[callee.object.name='Error'][callee.property.name='captureStackTrace']",
message: "Use 'hideStackFrames' from 'internal/errors' instead.", message: "Use 'hideStackFrames' from 'internal/errors' instead.",
}, },
{
selector: "CallExpression[callee.object.name='URL'][callee.property.name='parse']",
message: "Use 'URLParse' from 'internal/url' instead.",
},
{ {
selector: "AssignmentExpression:matches([left.object.name='Error']):matches([left.name='prepareStackTrace'], [left.property.name='prepareStackTrace'])", selector: "AssignmentExpression:matches([left.object.name='Error']):matches([left.name='prepareStackTrace'], [left.property.name='prepareStackTrace'])",
message: "Use 'overrideStackTrace' from 'internal/errors' instead.", message: "Use 'overrideStackTrace' from 'internal/errors' instead.",

View File

@@ -37,7 +37,7 @@ const {
kDeserialize, kDeserialize,
} = require('internal/worker/js_transferable'); } = require('internal/worker/js_transferable');
const { URL } = require('internal/url'); const { URLParse } = require('internal/url');
const kHandle = Symbol('kHandle'); const kHandle = Symbol('kHandle');
const kDetail = Symbol('kDetail'); const kDetail = Symbol('kDetail');
@@ -156,7 +156,7 @@ class SocketAddress {
const { const {
hostname: address, hostname: address,
port, port,
} = URL.parse(`http://${input}`); } = URLParse(`http://${input}`);
if (address.startsWith('[') && address.endsWith(']')) { if (address.startsWith('[') && address.endsWith(']')) {
return new SocketAddress({ return new SocketAddress({
address: address.slice(1, -1), address: address.slice(1, -1),

View File

@@ -30,7 +30,7 @@ const {
fileURLToPath, fileURLToPath,
isURL, isURL,
pathToFileURL, pathToFileURL,
URL, URLParse,
} = require('internal/url'); } = require('internal/url');
const { const {
emitExperimentalWarning, emitExperimentalWarning,
@@ -652,7 +652,7 @@ class MockTracker {
if (format) { // Format is not yet known for ambiguous files when detection is enabled. if (format) { // Format is not yet known for ambiguous files when detection is enabled.
validateOneOf(format, 'format', kSupportedFormats); validateOneOf(format, 'format', kSupportedFormats);
} }
const baseURL = URL.parse(url); const baseURL = URLParse(url);
if (!baseURL) { if (!baseURL) {
throw new ERR_INVALID_ARG_VALUE( throw new ERR_INVALID_ARG_VALUE(