Adds the latin1 characters to the ascii block to avoid splitting words

This commit is contained in:
Vitor Pamplona
2026-03-04 14:38:48 -05:00
parent be5c1f4832
commit 2f94b3cb15
2 changed files with 16 additions and 1 deletions
@@ -348,7 +348,7 @@ class RichTextParser {
// Splits at spaces AND at ASCII/multibyte character boundaries
// e.g. "ああexample.com" -> ["ああ", "example.com"]
private val wordBoundaryRegex = Regex("(?<=[\\u0000-\\u007F])(?=[\\u0080-\\uFFFF])|(?<=[\\u0080-\\uFFFF])(?=[\\u0000-\\u007F])| +")
val wordBoundaryRegex = Regex("(?<=[\\u0000-\\u007F])(?=[\\u0080-\\uFFFF])|(?<=[\\u0080-\\uFFFF])(?=[\\u0000-\\u007F])| +")
val additionalUrlSchema =
"""^([A-Za-z0-9-_]+(\.[A-Za-z0-9-_]+)+)(:[0-9]+)?(/[^?#]*)?(\?[^#]*)?(#.*)?"""
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.commons.richtext
import com.vitorpamplona.amethyst.commons.model.EmptyTagList
import org.junit.Assert.assertTrue
import org.junit.Test
import kotlin.test.assertEquals
class RichTextParserMultibyteTest {
@Test
@@ -58,6 +59,20 @@ class RichTextParserMultibyteTest {
)
}
@Test
fun testFullTextWithMultibyteAndLatinAccents() {
// Multibyte characters around an email address should not produce URL/Link segments
val text =
"Vitor, você tem como colocar alguma forma de aviso se o link vai carregar uma imagem ou um vídeo? \uD83E\uDD7A"
val regex = Regex("(?<=[\\u0000-\\u00FF])(?=[\\u0100-\\uFFFF])|(?<=[\\u0100-\\uFFFF])(?=[\\u0000-\\u00FF])| +")
assertEquals(
"Vitor,-você-tem-como-colocar-alguma-forma-de-aviso-se-o-link-vai-carregar-uma-imagem-ou-um-vídeo?-\uD83E\uDD7A",
text.split(regex).joinToString("-"),
)
}
@Test
fun testEmailSegmentStandalone() {
val text = "user@example.com"