Skip to content

Image before link crashes renderer #661

Description

@mikewesthad

Describe the bug

Using react-native-enriched, email that feature an image before a link crash the renderer.

To Reproduce

Pass this html into EnrichedTextInput

<html><img src="data:," /><img src="data:," /><img src="data:," /><p>See <a href="https://example.com">a link</a></p></html>

Get this crash

*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
    reason: '-[__NSCFString substringWithRange:]: Range {7, 6} out of bounds; string length 10'

Root cause: HtmlParser.mm:698 does [plainText substringWithRange:tagRangeValue.rangeValue] where the range was built at :166 in final-NSTextStorage coords (counts +1 per ), but plainText doesn’t contain the image placeholders. Any link finalized while precedingImageCount > 0 overruns plainText by that count. Triggered in our app on a real ~5.3KB email with 3 images and a trailing link (overrun by 3, matching the math). Fix is a one-site clamp before :698.

Expected behavior
HTML should not crash

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions