Fix issue #1174 with span parsing (#1183)

main
Levi Bard 6 years ago committed by Konrad Pozniak
parent a91dea7c60
commit 23920a61ee
  1. 5
      app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt
  2. 2
      app/src/test/java/com/keylesspalace/tusky/SpanUtilsTest.kt

@ -70,7 +70,10 @@ private fun findPattern(string: String, fromIndex: Int): FindCharsResult {
result.matchType = matchType
result.start = Math.max(0, i - finder.searchPrefixWidth)
findEndOfPattern(string, result, finder.pattern)
return result
if (result.start + finder.searchPrefixWidth <= i + 1 && // The found result is actually triggered by the correct search character
result.end >= result.start) { // ...and we actually found a valid result
return result
}
}
}
}

@ -10,7 +10,7 @@ import org.junit.runners.Parameterized
class SpanUtilsTest {
@Test
fun matchesMixedSpans() {
val input = "one #one two @two three https://thr.ee/meh?foo=bar&wat=@at#hmm four #four five @five"
val input = "one #one two: @two three : https://thr.ee/meh?foo=bar&wat=@at#hmm four #four five @five"
val inputSpannable = FakeSpannable(input)
highlightSpans(inputSpannable, 0xffffff)
val spans = inputSpannable.spans

Loading…
Cancel
Save