Fix address_is_local to match .local case-insensitively#1681
Conversation
mDNS and DNS names are case-insensitive per RFC 6762 §16 / RFC 4343,
but address_is_local() does a case-sensitive endswith(".local") so
"MyESP.LOCAL" is rejected. These parametrized cases pin the expected
behaviour; they fail against the current implementation.
mDNS hostnames are case-insensitive (RFC 6762 §16, RFC 4343), but
address_is_local() used a case-sensitive endswith(".local") so an
address advertised as "MyESP.LOCAL" or with a mixed-case TLD was
not recognised as local. Lowercase before comparing.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1681 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 25
Lines 4152 4152
=========================================
Hits 4152 4152 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe PR updates the ChangesCase-insensitive mDNS/local address detection
🎯 2 (Simple) | ⏱️ ~8 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes address_is_local() so it treats .local as case-insensitive (consistent with DNS/mDNS), ensuring mixed-case mDNS hostnames are correctly recognized as local and therefore can be used as the friendly name source in build_log_name().
Changes:
- Make
address_is_local()lowercase the address before checking for the.localsuffix (while preserving trailing-dot handling). - Add unit tests covering
.localcase-insensitive behavior and trailing-dot variants.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| aioesphomeapi/util.py | Adjusts .local detection to be case-insensitive by lowercasing before the suffix check. |
| tests/test_util.py | Adds parametrized tests verifying case-insensitive .local recognition and existing edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What does this implement/fix?
What:
address_is_local()now lowercases the address beforechecking the
.localsuffix.Why: mDNS / DNS names are case-insensitive (RFC 6762 §16,
RFC 4343), but the previous
endswith(".local")was case-sensitive.A peer advertising itself as
MyESP.LOCALormyesp.Localwas notrecognised as a local address, which then perturbs the log-name
composition in
build_log_name()(the(not name and address_is_local(address))branch never fires, so the host partisn't lifted out as the friendly name).
How: One-character behavioural change —
.lower()before.endswith(".local"). Trailing-dot handling (removesuffix("."))is preserved.
Testing: New parametrized
test_address_is_localcases pin thecase-insensitive behaviour (commit 1 fails against the old code,
commit 2 makes them pass). Full suite:
1075 passed, 2 skipped.Types of changes
Related issue or feature (if applicable):
targeted bug fix that surfaced while writing those tests).
Pull request in esphome (if applicable):
Checklist:
tests/folder).Quality Report
Changes: 2 files changed, 21 insertions(+), 2 deletions(-)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline