Make URLSpans with trailing URL not marked up (#2813)
This commit is contained in:
parent
3bc1fc4606
commit
d1482324cc
2 changed files with 36 additions and 0 deletions
|
@ -78,6 +78,7 @@ fun markupHiddenUrls(context: Context, content: CharSequence): SpannableStringBu
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
val text = spannableContent.subSequence(start, spannableContent.getSpanEnd(it)).toString()
|
val text = spannableContent.subSequence(start, spannableContent.getSpanEnd(it)).toString()
|
||||||
|
.split(' ').lastOrNull() ?: ""
|
||||||
var textDomain = getDomain(text)
|
var textDomain = getDomain(text)
|
||||||
if (textDomain.isBlank()) {
|
if (textDomain.isBlank()) {
|
||||||
textDomain = getDomain("https://$text")
|
textDomain = getDomain("https://$text")
|
||||||
|
|
|
@ -218,6 +218,41 @@ class LinkHelperTest {
|
||||||
Assert.assertFalse(markedUpContent.contains("🔗"))
|
Assert.assertFalse(markedUpContent.contains("🔗"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun spanEndsWithUrlIsNotMarkedUp() {
|
||||||
|
val content = SpannableStringBuilder()
|
||||||
|
.append("Some Place: some.place", URLSpan("https://some.place"), 0)
|
||||||
|
.append("Some Place: some.place/", URLSpan("https://some.place/"), 0)
|
||||||
|
.append("Some Place - https://some.place", URLSpan("https://some.place"), 0)
|
||||||
|
.append("Some Place | https://some.place/", URLSpan("https://some.place/"), 0)
|
||||||
|
.append("Some Place https://some.place/path", URLSpan("https://some.place/path"), 0)
|
||||||
|
|
||||||
|
val markedUpContent = markupHiddenUrls(context, content)
|
||||||
|
Assert.assertFalse(markedUpContent.contains("🔗"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun spanEndsWithFraudulentUrlIsMarkedUp() {
|
||||||
|
val content = SpannableStringBuilder()
|
||||||
|
.append("Another Place: another.place", URLSpan("https://some.place"), 0)
|
||||||
|
.append("Another Place: another.place/", URLSpan("https://some.place/"), 0)
|
||||||
|
.append("Another Place - https://another.place", URLSpan("https://some.place"), 0)
|
||||||
|
.append("Another Place | https://another.place/", URLSpan("https://some.place/"), 0)
|
||||||
|
.append("Another Place https://another.place/path", URLSpan("https://some.place/path"), 0)
|
||||||
|
|
||||||
|
val markedUpContent = markupHiddenUrls(context, content)
|
||||||
|
val asserts = listOf(
|
||||||
|
"Another Place: another.place",
|
||||||
|
"Another Place: another.place/",
|
||||||
|
"Another Place - https://another.place",
|
||||||
|
"Another Place | https://another.place/",
|
||||||
|
"Another Place https://another.place/path",
|
||||||
|
)
|
||||||
|
asserts.forEach {
|
||||||
|
Assert.assertTrue(markedUpContent.contains(context.getString(R.string.url_domain_notifier, it, "some.place")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun validMentionsAreNotMarkedUp() {
|
fun validMentionsAreNotMarkedUp() {
|
||||||
val builder = SpannableStringBuilder()
|
val builder = SpannableStringBuilder()
|
||||||
|
|
Loading…
Reference in a new issue