Skip to content

Commit d8f1dea

Browse files
aduh95RafaelGSS
authored andcommitted
lib: enforce use of URLParse
There's no reason to use the user-mutable `URL.parse` in core. PR-URL: #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>
1 parent 4a22647 commit d8f1dea

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎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
constkHandle=Symbol('kHandle');
4343
constkDetail=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
returnnewSocketAddress({
162162
address: address.slice(1,-1),

‎lib/internal/test_runner/mock/mock.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const {
3030
fileURLToPath,
3131
isURL,
3232
pathToFileURL,
33-
URL,
33+
URLParse,
3434
}=require('internal/url');
3535
const{
3636
emitExperimentalWarning,
@@ -652,7 +652,7 @@ class MockTracker {
652652
if(format){// Format is not yet known for ambiguous files when detection is enabled.
653653
validateOneOf(format,'format',kSupportedFormats);
654654
}
655-
constbaseURL=URL.parse(url);
655+
constbaseURL=URLParse(url);
656656

657657
if(!baseURL){
658658
thrownewERR_INVALID_ARG_VALUE(

0 commit comments

Comments
 (0)