[Bug] Seems to break with certain emoji strings
Opened this issue ยท 7 comments
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
bumblebee/Sources/bumblebee.swift
Line 90 in 842fb80
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!
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)
Is fixed in #29 if you'd like to take a look ๐
Hey @codeOfRobin I still had the issue with your PR.
I submitted a new one #31
Interesting @CWalig ๐ค. Could you point me to a failing test case so I can check it out?
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 ๐
@CWalig I wrote a test case specifically to make sure it worked ๐ค https://github.com/daltoniam/bumblebee/pull/29/files#diff-3c95b3eb97e5e17dbd3db4ad8fa45c2e
I know, this one has a different breakingString
and different rangeToCompare
.
Have you tried it? ๐ค