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

Searching for attributed text crashes when the text does not exist #23

Closed
theextremeprogrammer opened this issue Mar 10, 2019 · 0 comments
Assignees
Labels

Comments

@theextremeprogrammer
Copy link
Owner

There's a forced unwrapped optional when looking for the search string in an attributed string:

https://github.com/derekleerock/Succinct/blob/413cda993cbbe6011feec8cdb7a6edf1939a9436/Succinct/NSAttributedString/NSAttributedString%2Battributes.swift#L13

Therefore when a search string that doesn't exist in the attributed string is searched for, the function crashes.

Here's a test that re-creates this issue:

context("when the search string does not exist in the attributed string") {
    it("cannot find the string") {
        let redForegroundColor = [NSAttributedString.Key.foregroundColor : UIColor.red]
        let mutableAttributedString = NSMutableAttributedStringBuilder(withText: "Foreground and Background")
            .withAttributes(
                redForegroundColor,
                range: NSRange(location: 0, length: 10)
            )
            .build()


        let attributedString = mutableAttributedString.copy() as! NSAttributedString
        expect(attributedString.containsExactString("Invalid", withAttributes: redForegroundColor)).to(beTrue())
    }
}

Can you add this test and adjust the code to make it pass? Thanks!

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

No branches or pull requests

2 participants