Fix detecting urls (#4642)

closes #4641
This commit is contained in:
Konrad Pozniak 2024-09-02 19:56:38 +02:00 committed by GitHub
parent 31e4f08966
commit 4d73a3c2e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 3 deletions

View File

@ -66,7 +66,7 @@ fun Spannable.highlightSpans(colour: Int, finders: List<PatternFinder> = default
for (finder in finders) {
// before running the regular expression, check if there is even a chance of it finding something
if (this.contains(finder.searchString)) {
if (this.contains(finder.searchString, ignoreCase = true)) {
val matcher = finder.pattern.matcher(this)
while (matcher.find()) {

View File

@ -115,6 +115,10 @@ class SpanUtilsTest(
arrayOf("😜https://connyduck.at", listOf(2 to 22)),
arrayOf("😜#tag", listOf(2 to 6)),
arrayOf("😜@user@mastodon.example", listOf(2 to 24)),
// case should be ignored on protocols https://github.com/tuskyapp/Tusky/issues/4641
arrayOf("HTTPS://example.com", listOf(0 to 19)),
arrayOf("Http://example.com/test", listOf(0 to 23)),
arrayOf("test Https://example.com/test", listOf(5 to 29)),
)
}

View File

@ -43,7 +43,7 @@ class StatusLengthTest(
arrayOf("🫣", 1),
// "@user@server" should be treated as "@user"
arrayOf("123 @example@example.org", 12),
// URLs under 23 chars are treated as 23 chars
// URLs are always treated as 23 even if they are shorter
arrayOf("123 http://example.org", 27),
// URLs over 23 chars are treated as 23 chars
arrayOf("123 http://urlthatislongerthan23characters.example.org", 27),
@ -52,7 +52,11 @@ class StatusLengthTest(
// Long hashtags are *also* treated as is (not treated as 23, like URLs)
arrayOf("123 #atagthatislongerthan23characters", 37),
// urls can have balanced parenthesis, otherwise they are ignored https://github.com/tuskyapp/Tusky/issues/4425
arrayOf("(https://en.wikipedia.org/wiki/Beethoven_(horse))", 25)
arrayOf("(https://en.wikipedia.org/wiki/Beethoven_(horse))", 25),
// protocols can have any case https://github.com/tuskyapp/Tusky/issues/4641
arrayOf("Http://example.org", 23),
arrayOf("HTTPS://example.org", 23),
arrayOf("HTTPS://EXAMPLE.ORG", 23)
)
}
}