Skip to content

Escape feed-controlled data in Telegram HTML messages - #2251

Merged
fengkx merged 1 commit into
masterfrom
cursor/fix-html-escaping-7548
Oct 22, 2026
Merged

fengkx merged 1 commit into
masterfrom
cursor/fix-html-escaping-7548

Conversation

@fengkx

@fengkx fengkx commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

This PR fixes HTML escaping in Telegram messages to prevent feed-controlled and user-controlled data from breaking message formatting or being misinterpreted as HTML markup.

Rebased onto master after PR #2250 merge (commit 358ca54). Both changes now work together: notification templates use fixed EJS templates with escaped locals (PR #2250), while feed item messages escape URLs and sanitize titles (this PR).

Changes

New utility

  • Added source/utils/escape-html.ts: HTML escape helper for URLs and raw data that preserves exact formatting (wraps escapeHTML from fast-escape-html)

Consistent function usage

  • escapeHtml() for URLs and raw data (escapes HTML, preserves whitespace)
  • sanitize() for titles and content (escapes HTML + normalizes whitespace by removing newlines and collapsing spaces)

Fixed locations

  1. source/utils/send.ts: Escape item.link in href attributes and when used as fallback link text (when title is empty)
  2. source/middlewares/sub-multi-url.ts: Escape URLs in href, sanitize feed titles in subscription success messages
  3. source/middlewares/import-from-opml.ts: Escape URLs in href, sanitize OPML outline text in import success messages
  4. source/controlers/rss.ts: Escape URLs in href attributes and decoded URLs displayed as text (raw RSS list and viewAll)

Readability improvements

  • Enhanced documentation to clarify when to use escapeHtml() (URLs/raw data) vs sanitize() (titles/content)
  • Extracted repeated patterns into clear local variables (e.g., in send.ts)
  • Added clarifying comments at output-building call sites
  • Improved test organization with descriptive nested describe blocks

Testing

  • test/escape-html.spec.ts: 12 tests for the escapeHtml utility
  • test/html-escaping.spec.ts: 28 tests covering:
    • Special characters: &, <, >, ", '
    • Chinese text preservation
    • Plain inputs (output unchanged)
    • URLs with query parameters
    • Whitespace normalization in feed titles and OPML text (new in rebase)
    • Complete message formatting

Total test suite: 19 suites, 116 tests (all passing)

Behavior Changes

  • Changed: Special characters (&, <, >, ", ') in URLs and titles are now escaped and display literally in Telegram
  • Changed: Feed titles and OPML outline text have whitespace normalized (newlines removed, multiple spaces collapsed)
  • Unchanged: Plain inputs without special characters or extra whitespace produce identical output

Integration with PR #2250

Open in Web Open in Cursor 

- Add escapeHtml utility for HTML-safe output in Telegram messages (URLs, raw data)
- Use sanitize() consistently for titles (escapes HTML + normalizes whitespace)
- Fix unescaped URLs in send.ts feed item links (href and fallback text)
- Fix unescaped URLs in sub-multi-url.ts subscription success messages
- Fix unescaped URLs in import-from-opml.ts import success messages
- Fix unescaped URLs in rss.ts feed lists (raw and viewAll modes)
- Add comprehensive tests for HTML escaping and whitespace normalization (28 tests)

Readability improvements:
- Enhanced documentation clarifying when to use escapeHtml() vs sanitize()
- Extracted repeated expressions into clear local variables
- Added clarifying comments at output-building call sites
- Organized tests with descriptive nested describe blocks

Behavior changes:
- Special characters (&, <, >, ", ') in URLs and titles are now escaped
- Feed titles and OPML outline text have whitespace normalized (newlines removed, spaces collapsed)
- Plain inputs without special characters or extra whitespace produce identical output

Co-authored-by: fengkx <liangkx8237@gmail.com>
@cursor
cursor Bot force-pushed the cursor/fix-html-escaping-7548 branch from f4d5bc0 to 9847b75 Compare October 22, 2026 08:13
@fengkx
fengkx marked this pull request as ready for review October 22, 2026 08:15
@fengkx
fengkx merged commit 63431f3 into master Oct 22, 2026
5 of 6 checks passed
@fengkx fengkx mentioned this pull request Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants