Skip to content

Commit 3c4541f

Browse files
pckrishnadas88richardlau
authored andcommitted
lib: simplify IPv6 checks in isLoopback()
The checks for '[::1]' and '[0:0:0:0:0:0:0:1]' in isLoopback were using startsWith, which is unnecessary as these are canonical loopback addresses with no valid prefixes. Switching to strict equality improves clarity and improves performance. PR-URL: #59375 Reviewed-By: Tim Perry <[email protected]> Reviewed-By: theanarkh <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ulises Gascón <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Stefan Stojanovic <[email protected]>
1 parent 77682b5 commit 3c4541f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/internal/net.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ function isLoopback(host) {
7979
return (
8080
hostLower === 'localhost' ||
8181
hostLower.startsWith('127.') ||
82-
hostLower.startsWith('[::1]') ||
83-
hostLower.startsWith('[0:0:0:0:0:0:0:1]')
82+
hostLower === '[::1]' ||
83+
hostLower === '[0:0:0:0:0:0:0:1]'
8484
);
8585
}
8686

0 commit comments

Comments
 (0)