Skip to content

Commit c7be984

Browse files
committed
lib: enforce use of URLParse
There's no reason to use the user-mutable `URL.parse` in core.
1 parent 83ba6b1 commit c7be984

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/eslint.config_partial.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const noRestrictedSyntax = [
3030
selector: "CallExpression[callee.object.name='Error'][callee.property.name='captureStackTrace']",
3131
message: "Use 'hideStackFrames' from 'internal/errors' instead.",
3232
},
33+
{
34+
selector: "CallExpression[callee.object.name='URL'][callee.property.name='parse']",
35+
message: "Use 'URLParse' from 'internal/url' instead.",
36+
},
3337
{
3438
selector: "AssignmentExpression:matches([left.object.name='Error']):matches([left.name='prepareStackTrace'], [left.property.name='prepareStackTrace'])",
3539
message: "Use 'overrideStackTrace' from 'internal/errors' instead.",

lib/internal/socketaddress.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const {
3737
kDeserialize,
3838
} = require('internal/worker/js_transferable');
3939

40-
const { URL } = require('internal/url');
40+
const { URLParse } = require('internal/url');
4141

4242
const kHandle = Symbol('kHandle');
4343
const kDetail = Symbol('kDetail');
@@ -156,7 +156,7 @@ class SocketAddress {
156156
const {
157157
hostname: address,
158158
port,
159-
} = URL.parse(`http://${input}`);
159+
} = URLParse(`http://${input}`);
160160
if (address.startsWith('[') && address.endsWith(']')) {
161161
return new SocketAddress({
162162
address: address.slice(1, -1),

lib/internal/test_runner/mock/mock.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const {
3131
isURL,
3232
pathToFileURL,
3333
URL,
34+
URLParse,
3435
} = require('internal/url');
3536
const {
3637
emitExperimentalWarning,
@@ -652,7 +653,7 @@ class MockTracker {
652653
if (format) { // Format is not yet known for ambiguous files when detection is enabled.
653654
validateOneOf(format, 'format', kSupportedFormats);
654655
}
655-
const baseURL = URL.parse(url);
656+
const baseURL = URLParse(url);
656657

657658
if (!baseURL) {
658659
throw new ERR_INVALID_ARG_VALUE(

0 commit comments

Comments
 (0)