From c4eade463c433bfcc2f1314c8ea588775c284283 Mon Sep 17 00:00:00 2001 From: chenhg5 Date: Mon, 9 Mar 2026 15:21:35 +0800 Subject: [PATCH] fix(feishu): validate URLs before creating hyperlinks Add URL validation for Feishu post hyperlinks to prevent rejection of non-HTTP(S) URLs. Skip invalid links during markdown parsing. generated by llmgit Co-Authored-By: Claude --- platform/feishu/feishu.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/platform/feishu/feishu.go b/platform/feishu/feishu.go index 8f7e9cf..df924eb 100644 --- a/platform/feishu/feishu.go +++ b/platform/feishu/feishu.go @@ -595,6 +595,12 @@ func buildPostJSON(content string) string { return string(b) } +// isValidFeishuHref checks whether a URL is acceptable as a Feishu post href. +// Feishu rejects non-HTTP(S) URLs with "invalid href" (code 230001). +func isValidFeishuHref(u string) bool { + return strings.HasPrefix(u, "http://") || strings.HasPrefix(u, "https://") +} + // parseInlineMarkdown parses a single line of markdown into Feishu post elements. // Supports **bold** and `code` inline formatting. func parseInlineMarkdown(line string) []map[string]any { @@ -638,18 +644,20 @@ func parseInlineMarkdown(line string) []map[string]any { } } if !foundEarlierMarker { - if linkIdx > 0 { - elements = append(elements, map[string]any{"tag": "text", "text": remaining[:linkIdx]}) - } linkText := remaining[linkIdx+1 : bracketClose] linkURL := remaining[bracketClose+2 : parenClose] - elements = append(elements, map[string]any{ - "tag": "a", - "text": linkText, - "href": linkURL, - }) - remaining = remaining[parenClose+1:] - continue + if isValidFeishuHref(linkURL) { + if linkIdx > 0 { + elements = append(elements, map[string]any{"tag": "text", "text": remaining[:linkIdx]}) + } + elements = append(elements, map[string]any{ + "tag": "a", + "text": linkText, + "href": linkURL, + }) + remaining = remaining[parenClose+1:] + continue + } } } }