Skip to content

Commit 9a12f71

Browse files
pckrishnadas88targos
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 <pimterry@gmail.com> Reviewed-By: theanarkh <theratliter@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
1 parent 52ab64e commit 9a12f71

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
@@ -93,8 +93,8 @@ function isLoopback(host) {
9393
return (
9494
hostLower === 'localhost' ||
9595
hostLower.startsWith('127.') ||
96-
hostLower.startsWith('[::1]') ||
97-
hostLower.startsWith('[0:0:0:0:0:0:0:1]')
96+
hostLower === '[::1]' ||
97+
hostLower === '[0:0:0:0:0:0:0:1]'
9898
);
9999
}
100100

0 commit comments

Comments
 (0)