Skip to content

Commit eed1d33

Browse files
pckrishnadas88pimterry
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 fc3f19e commit eed1d33

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)