Fix linkify for valid URLs with ... in the path.

This commit is contained in:
Cody Henthorne
2023-06-15 10:11:06 -04:00
parent 0437d37f23
commit 1c5e2e3359
3 changed files with 9 additions and 7 deletions

View File

@@ -67,18 +67,18 @@ object LinkUtil {
return LegalCharactersResult(false)
}
if (ILLEGAL_PERIODS_PATTERN.matcher(url).find()) {
return LegalCharactersResult(false)
}
val matcher = DOMAIN_PATTERN.matcher(url)
if (!matcher.matches()) {
return LegalCharactersResult(false)
}
val domain = Objects.requireNonNull(matcher.group(2))
val cleanedDomain = domain.replace("\\.".toRegex(), "")
if (ILLEGAL_PERIODS_PATTERN.matcher(domain).find()) {
return LegalCharactersResult(false)
}
val cleanedDomain = domain.replace("\\.".toRegex(), "")
return LegalCharactersResult(
isLegal = ALL_ASCII_PATTERN.matcher(cleanedDomain).matches() || ALL_NON_ASCII_PATTERN.matcher(cleanedDomain).matches(),
domain = domain

View File

@@ -45,7 +45,8 @@ public class LinkUtilTest_isLegal {
{ "cool.localhost", true },
{ "localhost", true },
{ "https://localhost", true },
{ "cool.test", true }
{ "cool.test", true },
{ "https://github.com/signalapp/Signal-Android/compare/v6.23.2...v6.23.3", true }
});
}

View File

@@ -50,7 +50,8 @@ class LinkUtilTest_isValidPreviewUrl(private val input: String, private val outp
arrayOf("https://cool.test", false),
arrayOf("https://cool.invalid.com", true),
arrayOf("https://cool.localhost.signal.org", true),
arrayOf("https://cool.test.blarg.gov", true)
arrayOf("https://cool.test.blarg.gov", true),
arrayOf("https://github.com/signalapp/Signal-Android/compare/v6.23.2...v6.23.3", true)
)
}
}