Skip to content

fix(android): Escape HTML attribute values - #865

Merged
szydlovsky merged 3 commits into
mainfrom
@szydlovsky/fix-android-html-escaping
Nov 19, 2026
Merged

szydlovsky merged 3 commits into
mainfrom
@szydlovsky/fix-android-html-escaping

Conversation

@szydlovsky

Copy link
Copy Markdown
Collaborator

Summary

Android was writing link href, image src and mention attribute values into the output HTML without escaping them. A value containing " or & (e.g. https://example.com/a&b"c) broke out of its attribute, so the HTML came out invalid and attributes could be injected. Because of this, the link_href_attribute_escaping e2e flow added in #849 fails on Android.

This brings Android in line with iOS, which got the same escaping in #849.

Changes

  • Added an escapeAttribute() helper to EnrichedParser that escapes &, <, > and ".
  • Used it for link href, image src, and mention text, indicator and custom attributes.
  • The span style attribute already escaped these characters inline; it now uses the same helper.

Reading HTML back in needs no changes, because the parser already decodes entities in attribute values, so escaped values come back as the original strings.

Test Plan

  • Run yarn test:e2e:android .maestro/enrichedInput/flows/link_href_attribute_escaping.yaml. The output now contains href="https://example.com/a&amp;b&quot;c", and setting that HTML again gives the same output (no double escaping).
  • In the example app, add a link whose URL contains " and &, check the HTML output, then set that HTML back and check that the link's URL is unchanged.

Compatibility

OS Implemented
iOS ✅ (#849)
Android ✅
Web ❌

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Link href, image src and mention attributes were written to HTML without
escaping, so a value containing `"` or `&` (e.g. https://example.com/a&b"c)
broke out of the attribute. Escape them the same way span style attributes
already were, matching the iOS fix from #849.

Fixes the link_href_attribute_escaping e2e flow on Android.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011B8KVetRzS7b2SUyxrrhgS
@szydlovsky
szydlovsky requested review from exploIF and a balanced review from Copilot November 13, 2026 16:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the Android HTML attribute-escaping changes.

No open issues 🎉

What changed in this PR

This PR escapes HTML attribute values during Android serialization, aligning behavior with the iOS changes in #849 and preventing values from breaking out of double-quoted attributes.

Changes:

  • Adds a shared helper to escape &, <, > and ".
  • Applies escaping to link URLs, image sources, and mention attribute values.
  • Reuses the helper for existing span-style escaping.
File Description
android/​src/​main/​java/​com/​swmansion/​enriched/​common/​parser/​EnrichedParser.java Centralizes attribute escaping and applies it to links, images, mentions, and span styles.

Review effort: Balanced

@szydlovsky
szydlovsky merged commit 242e31c into main Nov 19, 2026
14 of 16 checks passed
@szydlovsky
szydlovsky deleted the @szydlovsky/fix-android-html-escaping branch November 19, 2026 13:22
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.

3 participants