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

[Bug] Seems to break with certain emoji strings #28

Open
codeOfRobin opened this issue Feb 15, 2018 · 7 comments
Open

[Bug] Seems to break with certain emoji strings #28

codeOfRobin opened this issue Feb 15, 2018 · 7 comments

Comments

@codeOfRobin
Copy link

Hey @daltoniam !

I just tried running an emoji-laden string past MDEmphasisPattern, and it seems to crash with an Fatal error: cannot increment beyond endIndex in

let end = mutText.index(mutText.startIndex, offsetBy: range.location + range.length)

I have a fork with a test case added, but I've messed with a lot of build settings(from xcodegen: https://github.com/yonaskolb/XcodeGen) and don't think you'd want to merge. Check this out if you're interested though: codeOfRobin@62d6c4d

I'll try fixing it in my spare time, but I'd love to hear your thoughts on it!

@codeOfRobin
Copy link
Author

codeOfRobin commented Feb 15, 2018

Here's the code in case you wanna check it out yourself:

let breakingString = " *hello* .  *hello*  cncnc cncnc  *hello*  hmm\n  *hello*  🦌🐎🦌🐎\n  *hello*  Screen Shot 2017-10-12 at 11.04.58 AM.png  *hello*  vVe2keakU8.gif  *hello*   *hello* "


let parser = Parser()

let parseExpectation = expectation(description: "parsing expectation")

parser.add(pattern: MDEmphasisPattern()) { (str, attributes) in
	return MatchedResponse(string: str, attributes: [:])
}

parser.process(text: breakingString) { (attrString) in
	guard let _ = attrString else {
		return
	}
	parseExpectation.fulfill()
}

wait(for: [parseExpectation], timeout: 10.0)

@codeOfRobin
Copy link
Author

Is fixed in #29 if you'd like to take a look 😄

@wes-nz
Copy link

wes-nz commented Mar 8, 2018

Hey @codeOfRobin I still had the issue with your PR.
I submitted a new one #31

@codeOfRobin
Copy link
Author

Interesting @CWalig 🤔. Could you point me to a failing test case so I can check it out?

@wes-nz
Copy link

wes-nz commented Mar 9, 2018

What about?

func testSingleEmoji() {
		let breakingString = "🐎🐎 *hello* "
   
		let parseExpectation = expectation(description: "parsing expectation")

		parser.add(pattern: MDEmphasisPattern()) { (str, attributes) in
			return MatchedResponse(string: str, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 10.0)])
		}

		parser.process(text: breakingString) { (attrString) in
			guard let attrString = attrString else {
				return
			}
			let rangeToCompare = NSRange.init(location: 4, length: 5)
			attrString.enumerateAttributes(in: NSRange(location: 0, length: attrString.string.count), options: [.longestEffectiveRangeNotRequired], using: { (value, range, isStop) in
                if range == rangeToCompare {
					parseExpectation.fulfill()
				}
			})
		}

		wait(for: [parseExpectation], timeout: 10.0)
    }

Let me know if I am missing something 👍

@codeOfRobin
Copy link
Author

@CWalig I wrote a test case specifically to make sure it worked 🤔 https://github.com/daltoniam/bumblebee/pull/29/files#diff-3c95b3eb97e5e17dbd3db4ad8fa45c2e

@wes-nz
Copy link

wes-nz commented Mar 9, 2018

I know, this one has a different breakingString and different rangeToCompare.
Have you tried it? 🤔

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

No branches or pull requests

2 participants