Skip to content

paragraphRange signature does not specify the returning type could be nullable, leading to unexpected crashes #1378

Description

@iamgabrielma

We've seen some crashes in WooCommerce for iOS coming from our AztecEditor wrapper. This seems to come from the underlying usage of paragraphRange, since assumes that the attachment passed into the method is the string, force-unwrapping the first result of the attachments array:

    func paragraphRange(for attachment: NSTextAttachment) -> NSRange {
        // We assume the attachment IS in the string.  This method should not be called otherwise.
        let attachmentRange = ranges(forAttachment: attachment).first!
        
        return paragraphRange(for: attachmentRange)
    }

This leads to unexpected crashes when the method is not used as intended, since its signature does not specify that the result could be nil. Ideally we should change the returning type to NSRange?, or handle the existence of nil values internally.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions