Skip to content

feat: add instance_name_unescaped() to get a readable instance name - #552

Merged
keepsimple1 merged 2 commits into
mainfrom
instance-name-helper
Nov 17, 2026
Merged

keepsimple1 merged 2 commits into
mainfrom
instance-name-helper

Conversation

@keepsimple1

@keepsimple1 keepsimple1 commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #540, before the 0.22.0 release (#551).

Problem

Since #540, a fullname read from the network keeps its RFC 6763 section 4.3 escapes, so it equals the registered fullname. For an instance named L.A.R.A Hub, ServiceFound, ServiceRemoved and ResolvedService.fullname now give L\.A\.R\.A Hub._lara._tcp.local.. To show the readable name, a user has to split the fullname on unescaped dots and remove the escapes themselves.

Change

Add one public function, mdns_sd::instance_name_unescaped(fullname: &str) -> String. It returns the first label of fullname with \. and \\ unescaped, i.e. the name given to ServiceInfo::new():

let fullname = r"L\.A\.R\.A Hub._lara._tcp.local.";
assert_eq!(instance_name_unescaped(fullname), "L.A.R.A Hub");
  • A backslash before any other character is kept, the same way the packet writer treats it.
  • It always returns a String. It doesn't validate fullname: it returns the part before the first unescaped dot, unescaped, or the whole string unescaped if there is no unescaped dot ("no-dot" gives "no-dot", "" gives ""). The fullnames it is meant for come from the daemon's own events, so callers shouldn't have to handle a None that never happens.
  • The docs say the result is for display: APIs that take a fullname still need the fullname itself.
  • The docs of ResolvedService.fullname, ResolvedService::get_fullname(), ServiceEvent::ServiceFound and ServiceEvent::ServiceRemoved now say the fullname is escaped and link to the new function.

This is deliberately minimal. Getters on ResolvedService / ServiceInfo or a whole-name unescape can be added later once we know what users need.

Tests

  • test_instance_name_unescaped: plain names, escaped dots and backslashes, \\ right before the separator dot, a stray backslash, UTF-8, and inputs that aren't fullnames.
  • test_instance_name_unescaped_round_trip: ServiceInfo::new(name) and then instance_name_unescaped(get_fullname()) gives back name.
  • A doc-test example.
  • test_rfc6763_utf8_network_integration now also checks that the resolved fullname gives back the registered instance name.

AI assistance: Claude Code

Since #540, a fullname read from the network keeps its RFC 6763 escapes,
e.g. "L\.A\.R\.A Hub._lara._tcp.local.". Add a public
instance_name_unescaped() that returns the first label of a fullname
unescaped ("L.A.R.A Hub").

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Note on ResolvedService.fullname, ResolvedService::get_fullname(),
ServiceEvent::ServiceFound and ServiceEvent::ServiceRemoved that the
fullname escapes dots and backslashes in the instance name, and link to
instance_name_unescaped().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@keepsimple1
keepsimple1 merged commit 1f7068e into main Nov 17, 2026
6 checks passed
@keepsimple1
keepsimple1 deleted the instance-name-helper branch November 17, 2026 04:29
keepsimple1 added a commit that referenced this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant