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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Krishnadas 2025-08-06 12:52:13 +05:30 committed by Tim Perry
parent fc3f19ef93
commit eed1d33c53
No known key found for this signature in database
GPG key ID: 0DDE38AFD3AF94F0

View file

@ -93,8 +93,8 @@ function isLoopback(host) {
return ( return (
hostLower === 'localhost' || hostLower === 'localhost' ||
hostLower.startsWith('127.') || hostLower.startsWith('127.') ||
hostLower.startsWith('[::1]') || hostLower === '[::1]' ||
hostLower.startsWith('[0:0:0:0:0:0:0:1]') hostLower === '[0:0:0:0:0:0:0:1]'
); );
} }