mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 12:56:01 -06:00
fix(terminal-core): tighten docs link URL detection
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user