Skip to content

Generating a highlighted attributed string crashes #13

Description

@kevmalek

In some cases, we see a crash when HighlightSwift calls func attributedTextFromData(_ data: Data) throws -> AttributedString. The init fails to create the string and mutableString.length is 0. As a result, the range length is invalid, causing the crash

Image

This could be because NSAttributedString.init(data:options:documentAttributes:) should only be called from the main thread when parsing html data.

See the documentation here: https://developer.apple.com/documentation/foundation/nsattributedstring/1524613-init

Don’t call this method from a background thread if the options dictionary includes the documentType attribute with a value of html. If you do, the method tries to synchronize with the main thread, fails, and times out. Calling it from the main thread works, but can still time out if the HTML contains references to external resources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions