Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/terminal-core/src/links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion packages/terminal-core/src/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
Loading