From a2fa49aafbe2d435aa3cbf1a05cd882afb377826 Mon Sep 17 00:00:00 2001 From: Levi Bard Date: Mon, 8 Apr 2019 15:27:41 +0200 Subject: [PATCH] Fix issue #1174 with span parsing (#1183) --- app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt | 5 ++++- app/src/test/java/com/keylesspalace/tusky/SpanUtilsTest.kt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt b/app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt index 01dcf02e..ec504038 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.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 + } } } } diff --git a/app/src/test/java/com/keylesspalace/tusky/SpanUtilsTest.kt b/app/src/test/java/com/keylesspalace/tusky/SpanUtilsTest.kt index 37e3a1be..f90a95e7 100644 --- a/app/src/test/java/com/keylesspalace/tusky/SpanUtilsTest.kt +++ b/app/src/test/java/com/keylesspalace/tusky/SpanUtilsTest.kt @@ -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