Skip to content

Commit 40ef803

Browse files
authored
Fix address_is_local to match .local case-insensitively (#1681)
1 parent 11fb7ee commit 40ef803

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

aioesphomeapi/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def host_is_name_part(address: str) -> bool:
4545

4646
def address_is_local(address: str) -> bool:
4747
"""Return True if the address is a local address."""
48-
return address.removesuffix(".").endswith(".local")
48+
return address.removesuffix(".").lower().endswith(".local")
4949

5050

5151
def is_ip_address(address: str | None) -> bool:

tests/test_util.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
from aioesphomeapi import util
8-
from aioesphomeapi.util import is_ip_address
8+
from aioesphomeapi.util import address_is_local, is_ip_address
99

1010

1111
@pytest.mark.parametrize(
@@ -119,3 +119,22 @@ async def _eager_task():
119119
)
120120
def test_is_ip_address(address: str | None, expected: bool) -> None:
121121
assert is_ip_address(address) is expected
122+
123+
124+
@pytest.mark.parametrize(
125+
("address", "expected"),
126+
[
127+
("myesp.local", True),
128+
("myesp.local.", True),
129+
# mDNS / DNS names are case-insensitive (RFC 6762 §16, RFC 4343).
130+
("MyESP.LOCAL", True),
131+
("myesp.Local", True),
132+
("MYESP.LOCAL.", True),
133+
("myesp", False),
134+
("myesp.localdomain", False),
135+
("host.example.com", False),
136+
("", False),
137+
],
138+
)
139+
def test_address_is_local(address: str, expected: bool) -> None:
140+
assert address_is_local(address) is expected

0 commit comments

Comments
 (0)