Skip to content

Commit dc3594e

Browse files
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.
1 parent 60a58f6 commit dc3594e

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)