fix(bonjour): harden DNS label truncation · openclaw/openclaw@16322d5
vincentkoc
·
2026-04-28
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -736,7 +736,7 @@ describe("gateway bonjour advertiser", () => {
|
736 | 736 | }); |
737 | 737 | |
738 | 738 | it("truncates service name exceeding 63-byte DNS label limit", async () => { |
739 | | -const longHostname = "app-41627eae5842473f9e05f139ea307277-7f9477f4d6-lqqzf"; |
| 739 | +const longHostname = "app-41627eae5842473f9e05f139ea307277-7f9477f4d6-lqqzf-abcdefghi"; |
740 | 740 | enableAdvertiserUnitMode(longHostname); |
741 | 741 | |
742 | 742 | const destroy = vi.fn().mockResolvedValue(undefined); |
@@ -755,6 +755,7 @@ describe("gateway bonjour advertiser", () => {
|
755 | 755 | // Both name and hostname must be within the 63-byte DNS label limit |
756 | 756 | expect(new TextEncoder().encode(serviceName).byteLength).toBeLessThanOrEqual(63); |
757 | 757 | expect(new TextEncoder().encode(hostname).byteLength).toBeLessThanOrEqual(63); |
| 758 | +expect(hostname).not.toMatch(/-$/); |
758 | 759 | |
759 | 760 | await started.stop(); |
760 | 761 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -185,7 +185,7 @@ function resolveSystemMdnsHostname(): string | null {
|
185 | 185 | |
186 | 186 | const MAX_DNS_LABEL_BYTES = 63; |
187 | 187 | |
188 | | -function truncateToDnsLabel(name: string): string { |
| 188 | +function truncateToDnsLabel(name: string, fallback = "OpenClaw"): string { |
189 | 189 | const encoder = new TextEncoder(); |
190 | 190 | const encoded = encoder.encode(name); |
191 | 191 | if (encoded.byteLength <= MAX_DNS_LABEL_BYTES) { |
@@ -195,7 +195,12 @@ function truncateToDnsLabel(name: string): string {
|
195 | 195 | const truncated = encoded.slice(0, MAX_DNS_LABEL_BYTES); |
196 | 196 | const decoded = new TextDecoder("utf-8", { fatal: false }).decode(truncated); |
197 | 197 | // Strip any replacement character from incomplete multi-byte sequence at the end |
198 | | -return decoded.replace(/\uFFFD$/, "").trim() || "OpenClaw"; |
| 198 | +return ( |
| 199 | +decoded |
| 200 | +.replace(/\uFFFD$/, "") |
| 201 | +.replace(/-+$/, "") |
| 202 | +.trim() || fallback |
| 203 | +); |
199 | 204 | } |
200 | 205 | |
201 | 206 | function safeServiceName(name: string) { |
@@ -373,6 +378,7 @@ export async function startGatewayBonjourAdvertiser(
|
373 | 378 | .replace(/\.local$/i, "") |
374 | 379 | .split(".")[0] |
375 | 380 | .trim() || "openclaw", |
| 381 | +"openclaw", |
376 | 382 | ); |
377 | 383 | const instanceName = |
378 | 384 | typeof opts.instanceName === "string" && opts.instanceName.trim() |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。