fix(terminal-core): tighten docs link URL detection

This commit is contained in:
linhongkuan
2026-06-29 10:14:18 +08:00
committed by GitHub
parent 4109755592
commit 6d658c70ea
2 changed files with 13 additions and 1 deletions
+10
View File
@@ -13,6 +13,16 @@ describe("formatDocsLink", () => {
expect(out).toBe("https://example.com/page");
});
it("preserves uppercase absolute HTTPS urls", () => {
const out = formatDocsLink("HTTPS://example.com/page", "page");
expect(out).toBe("HTTPS://example.com/page");
});
it("does not treat http-prefixed relative paths as absolute urls", () => {
const out = formatDocsLink("http-status", "HTTP status");
expect(out).toBe("https://docs.openclaw.ai/http-status");
});
it("treats whitespace-only path like an empty path and falls back to docs root", () => {
const out = formatDocsLink(" ", "root");
expect(out).toBe("https://docs.openclaw.ai");
+3 -1
View File
@@ -5,6 +5,8 @@ function resolveDocsRoot(): string {
return "https://docs.openclaw.ai";
}
const ABSOLUTE_HTTP_URL_RE = /^https?:\/\//i;
export function formatDocsLink(
path: string | undefined | null,
label?: string,
@@ -17,7 +19,7 @@ export function formatDocsLink(
// here unguarded. The typed contract says docsPath is required, but a
// handful of channel plugins and catalog rows leave it unset at runtime.
const url = trimmed
? trimmed.startsWith("http")
? ABSOLUTE_HTTP_URL_RE.test(trimmed)
? trimmed
: `${docsRoot}${trimmed.startsWith("/") ? trimmed : `/${trimmed}`}`
: docsRoot;