Skip to content

Commit

Permalink
ensure that the startsWith shifts to a case-insensitive regex
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Jul 4, 2024
1 parent 80923fa commit 8ecfda3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/util/eventedhttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ export class HAPConnection extends EventEmitter {
private static getLocalNetworkInterface(socket: Socket): string {
function formatIPv4MappedIPv6Address(address: string): string {
// Check if the address is an IPv4-mapped IPv6 address without the 'ffff:' part
if (address.startsWith("::") && !address.startsWith("::ffff:")) {
if (/^::(?!ffff:)/i.test(address)) {
// Attempt to correct the format by adding 'ffff:' after '::'
return address.replace("::", "::ffff:");
}
Expand All @@ -860,7 +860,7 @@ export class HAPConnection extends EventEmitter {
// Check if the address is an IPv4-Mapped IPv6 Address (e.g., ::ffff:192.0.2.128)
// These addresses are IPv6 addresses that represent an IPv4 address
// See: https://tools.ietf.org/html/rfc4291#section-2.5.5.2 for more details
if (localAddress.startsWith("::ffff:")) {
if (/^::ffff:/i.test(localAddress)) {
// Extract the IPv4 part from the IPv4-Mapped IPv6 address
// This converts the address from ::ffff:192.0.2.128 to 192.0.2.128
localAddress = localAddress.substring(7);
Expand Down

0 comments on commit 8ecfda3

Please sign in to comment.