:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(posthog-ai): keep malformed links from crashing markdown stripping (#114575)
Andrew Maguire5773f1b25942
diff --git a/frontend/src/lib/utils/markdown.test.ts b/frontend/src/lib/utils/markdown.test.tsindex f8760a449f4e..07195b31792a 100644--- a/frontend/src/lib/utils/markdown.test.ts+++ b/frontend/src/lib/utils/markdown.test.ts@@ -26,6 +26,10 @@ describe('markdown utils', () => {['[docs](/docs/guide)', `docs (${window.location.origin}/docs/guide)`],['[api](api/v1)', `api (${window.location.origin}/api/v1)`],+ // Links that URL rejects are kept as written+ ['[bad host](//[bad)', 'bad host (//[bad)'],+ ['[bad port](//host:99999)', 'bad port (//host:99999)'],+// Bold/italic/code stripped['**bold** and *italic*', 'bold and italic'],['`inline code`', 'inline code'],diff --git a/frontend/src/lib/utils/markdown.ts b/frontend/src/lib/utils/markdown.tsindex 15c3bfd96430..064138610227 100644--- a/frontend/src/lib/utils/markdown.ts+++ b/frontend/src/lib/utils/markdown.ts@@ -44,7 +44,12 @@ function resolveUrl(href: string): string {}// Relative URL - prefix with current originif (typeof window !== 'undefined') {- return new URL(href, window.location.origin).href+ try {+ return new URL(href, window.location.origin).href+ } catch {+ // marked accepts links that URL rejects, such as `//[bad`, and callers render this output+ return href+ }}return href}