Repository navigation
Description
[I used an AI to troubleshoot and found an issue that may help the project. I apologize in advance if the details are poor or lacking. This is my first attempt to give back for the years I've been enjoying this project!!]
Feature Request: Automatically Trim Whitespace from mDNS Hostnames
Summary
Please consider automatically trimming leading and trailing whitespace from the mDNS hostname field in WLED's WiFi Setup configuration.
Problem observed
I accidentally entered a trailing space in the mDNS hostname field. The value looked correct at a glance, but WLED retained and advertised the whitespace as part of the hostname.
The intended hostname was:
ecenter.local
However, WLED advertised:
ecenter .local
I confirmed this using Avahi network discovery. Its output showed:
hostname = [ecenter\032.local]
The \032 represents an ASCII space, confirming that the trailing whitespace was actually included in the advertised hostname.
This caused an application relying on mDNS discovery and hostname resolution (LedFX) to discover the WLED device but fail to resolve its hostname and add it successfully.
Suggested improvements
- Automatically trim leading and trailing whitespace when saving the mDNS hostname.
- Validate the resulting hostname against permitted hostname characters.
- Display a warning if invalid characters are entered.
- Ideally, apply the same validation wherever WLED accepts a hostname used for network discovery.
Suggested reproduction steps
- Open WLED's WiFi Setup configuration.
- Enter a hostname with an accidental trailing space (for example,
ecenter). - Save the configuration and allow WLED to advertise its mDNS hostname.
- Inspect the advertised hostname using an mDNS discovery tool.
- Observe that the hostname contains the encoded trailing space and that clients attempting to resolve the expected hostname may fail.
Expected behavior
WLED should automatically remove leading and trailing whitespace before saving and advertising the hostname, or clearly reject the entry with a useful validation message.
Why this matters
Trailing spaces are invisible in configuration fields and very easy to enter accidentally. This can create confusing networking problems that are difficult for users to diagnose, particularly with applications that depend on automatic device discovery.
This is a relatively small usability improvement that could prevent unnecessary troubleshooting and improve compatibility with other software.
I really appreciate the work that goes into WLED. It's an excellent project, and I've gotten a tremendous amount of enjoyment and usefulness out of it. I'd be happy to help test a fix.
Thank you for maintaining such a great project!
Activity
softhack007 commentedon Nov 29, 2026
@coderabbitai does mDNS have the same rules as DNS, so we could use our existing sanitizer function ?
WLED/wled00/util.cpp
Lines 146 to 147 in 5e852a8
coderabbitai commentedon Nov 29, 2026
Analysis chain
Script executed:
Length of output: 28013
web_search executed:
Check official RFC 6762 and RFC 6763, RFC 1123 and RFC 1035 for the precise rules for mDNS host names versus DNS host names and DNS-SD service instance names. Are hostname labels restricted to ASCII letters, digits and hyphens, including numeric-leading hostnames and 63-byte label limit? Can DNS-SD instance labels contain spaces and UTF-8? Cite the relevant RFC sections.Length of output: 18471
Script executed:
Length of output: 22059
@softhack007Yes. We can reuse the sanitizer for the mDNS hostname label, although the rules are not identical.mDNS permits a broader range of characters than the traditional DNS hostname convention. For compatibility with clients, it is sensible to use letters, digits and hyphens, with no leading or trailing hyphen. A label can be at most 63 bytes. See RFC 6762 §3 and RFC 8766 §5.3. This also matches WLED’s hostname-hardening guidance in
docs/securecode.instructions.md.The existing
sanitizeHostname()would turnecenterintoecenter. It also replaces internal spaces with hyphens, so it does more than trim whitespace.cmDNScurrently holds at most 32 characters, within the DNS label limit.There is one important gap:
getWLEDhostname()sanitizes a copy ofcmDNSfor the network hostname, butMDNS.begin()andArduinoOTA.setHostname()still receivecmDNSdirectly. The sanitizer is alsostatictoutil.cpp. Reusing it for those paths would require exposing it or adding a shared wrapper. If we normalize the stored value, we should handle both settings input and loaded configuration, while preserving an emptycmDNSas the mDNS-disable setting and retaining the default-name behavior.This recommendation applies to the hostname, not DNS-SD service instance names. Those can contain spaces and Unicode text (RFC 6763 §4.1.1).
Learnings used
You are interacting with an AI system.
trim mDNS hostname and SSIDs (fixes #5999)
hostname and mDNS robustness improvements (solves #5831 and #5999) (#…
softhack007 commentedon Dec 2, 2026
this is partly solved now, by trimming the mDNS name.
The mDNS name can still be malformed - this can be solved by using
sanitizeHostname(), however its a potentially breaking change => candidate for 17.0.[-]Feature Request: Automatically Trim Whitespace from mDNS Hostnames[/-][+]Feature Request: Automatically Trim Whitespace from mDNS Hostnames / sanitize mDNS Hostname[/+]hostname and mDNS robustness improvements (solves wled#5831 and wled#…