diff --git a/src/main/remote/channels/telegram/telegramMarkdown.ts b/src/main/remote/channels/telegram/telegramMarkdown.ts index cc660ebb75..bf4e21a639 100644 --- a/src/main/remote/channels/telegram/telegramMarkdown.ts +++ b/src/main/remote/channels/telegram/telegramMarkdown.ts @@ -37,9 +37,6 @@ const HTML_ESCAPE_MAP: Record = { const escapeHtml = (value: string): string => value.replace(/[&<>]/g, (char) => HTML_ESCAPE_MAP[char] ?? char) -const escapeAttribute = (value: string): string => - escapeHtml(value).replace(/"/g, '"').replace(/\n/g, ' ') - const sanitizeLanguage = (value: string): string => value.replace(/[^a-zA-Z0-9_+\-.]/g, '') const renderCodeBlock = (lang: string, body: string): string => { @@ -212,7 +209,8 @@ const renderLine = (line: string): { content: string; isBlockquote: boolean } => escaped = escaped.replace( /\[([^\]\n]+)\]\(([^)\s]+?)\)/g, (_match, label: string, url: string) => { - return `${label}` + // `escaped` already holds HTML-escaped text, so only the quote still needs escaping here. + return `${label}` } ) diff --git a/test/main/remote/telegramMarkdown.test.ts b/test/main/remote/telegramMarkdown.test.ts index 7901d18d0a..7450c931dd 100644 --- a/test/main/remote/telegramMarkdown.test.ts +++ b/test/main/remote/telegramMarkdown.test.ts @@ -66,6 +66,19 @@ describe('convertMarkdownToTelegramHtml', () => { ) }) + it('escapes an ampersand in a link URL only once', () => { + expect( + convertMarkdownToTelegramHtml( + '[Star History](https://star-history.dera.page/svg?repos=ThinkInAIXYZ/deepchat&type=Timeline)' + ) + ).toBe( + 'Star History' + ) + expect(convertMarkdownToTelegramHtml('[x](https://example.com/?a=1&b=2&c=<3>)')).toBe( + 'x' + ) + }) + it('normalizes unordered list markers to bullet points', () => { expect(convertMarkdownToTelegramHtml('- one\n* two\n+ three')).toBe('• one\n• two\n• three') })