fix: accept uppercase .local. trailer in service_type_name#1747
Conversation
DNS name comparisons are case-insensitive (RFC 1035 §2.3.3, RFC 6762 §16), so service_type_name should accept names such as "Localhost.LOCAL." or "_http._TCP.local." instead of rejecting them with BadTypeInNameException. Lowercase the input only for the endswith checks; the returned trailer still preserves the caller's original casing, so ServiceInfo's existing "type_.endswith(service_type_name(name))" check keeps working when both sides share the same case.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1747 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 33 33
Lines 3455 3456 +1
Branches 478 478
=======================================
+ Hits 3447 3448 +1
Misses 5 5
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Updates service_type_name() to treat the .local. / ._tcp.local. / ._udp.local. trailer as case-insensitive (per DNS rules) while preserving the caller’s original casing in the returned trailer, fixing mixed-case .LOCAL. inputs.
Changes:
- Normalize the input to
type_.lower()for trailer matching in both strict and non-strict parsing branches. - Add tests covering mixed-case strict trailers and the reported
Localhost.LOCAL.non-strict case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/zeroconf/_utils/name.py |
Makes trailer detection case-insensitive by comparing against constants using a lowercased view of the input. |
tests/utils/test_name.py |
Adds regression tests for mixed-case .LOCAL. trailer handling in strict and non-strict modes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ("_http._tcp.LOCAL.", "_http._tcp.LOCAL."), | ||
| ("_http._TCP.local.", "_http._TCP.local."), | ||
| ("_HTTP._tcp.local.", "_HTTP._tcp.local."), | ||
| ("Instance._http._tcp.LOCAL.", "_http._tcp.LOCAL."), |
PR Review — fix: accept uppercase .local. trailer in service_type_nameTight, well-scoped fix. Lowering 🟢 Suggestions1. Add a `_udp` mixed-case case to cover the second trailer constant (`tests/utils/test_name.py`, L64-71)The implementation matches against the tuple Checklist
SummaryTight, well-scoped fix. Lowering Automated review by Kōan8b1fc34 |
Rebase with requested adjustmentsBranch Changes applied
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
Summary
DNS name comparisons are case-insensitive (RFC 1035 §2.3.3, RFC 6762 §16), but
service_type_namerejected inputs whose.local./._tcp.local./._udp.local.trailer used any non-lowercase letter (e.g.Localhost.LOCAL.). This change normalises the input case for the trailer match only; the returned trailer still preserves the caller's original casing so existingtype_.endswith(service_type_name(name))checks inServiceInfokeep working.Fixes #1746
Changes
_utils/name.py: comparetype_.lower()against the trailer constants in both the strict (._tcp.local./._udp.local.) and non-strict (.local.) branches.tests/utils/test_name.py: cover mixed-case strict trailers and the issue's reportedLocalhost.LOCAL.non-strict case.Test plan
poetry run pytest tests/utils/test_name.py -v— new mixed-case cases pass.SKIP_CYTHON=1 poetry run pytest --timeout=60) — 372 passed, 2 skipped, no regressions.poetry run ruff check/ruff format --checkon touched files.Generated by Kōan /fix
Quality Report
Changes: 2 files changed, 23 insertions(+), 2 deletions(-)
Code scan: clean
Tests: passed (4 PASSED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline