Fix the tag span generation for tags with nonascii characters (#2700)

* Update mention and tag regexes from mastodon

* Normalize nonascii tag names the same way that mastodon does
This commit is contained in:
Levi Bard 2022-09-17 19:06:45 +02:00 committed by GitHub
commit 5d09a67b52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 3 deletions

View file

@ -38,6 +38,7 @@ class SpanUtilsTest {
return listOf(
"@mention",
"#tag",
"#tåg",
"https://thr.ee/meh?foo=bar&wat=@at#hmm",
"http://thr.ee/meh?foo=bar&wat=@at#hmm"
)

View file

@ -86,6 +86,17 @@ class LinkHelperTest {
}
}
@Test
fun whenCheckingTags_tagNameIsNormalized() {
val mutator = "aeiou".toList().zip("åÉîøÜ".toList()).toMap()
for (tag in tags) {
val mutatedTagName = String(tag.name.map { mutator[it] ?: it }.toCharArray())
val tagName = getTagName("#$mutatedTagName", tags)
Assert.assertNotNull(tagName)
Assert.assertNotNull(tags.firstOrNull { it.name == tagName })
}
}
@Test
fun hashedUrlSpans_withNoMatchingTag_areNotModified() {
for (tag in tags) {