Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iamgabrielma opened this issue Dec 5, 2023 · 0 comments

Comments

@iamgabrielma
Copy link

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.

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

No branches or pull requests

1 participant