mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 03:06:14 +00:00
Do not linkify the server part of a fediverse handle as an email address
A fediverse handle such as `@name@server.tld` contains a substring that `Linkify.EMAIL_ADDRESSES` recognises as a valid address, so the timeline renders `name@server.tld` as a tappable `mailto:` link. Tapping it opens a mail composer addressed to an account that does not accept mail. Drop a newly added `mailto:` span when the character immediately before it is `@`. This mirrors what Android already does for web URLs, where `Linkify.sUrlMatchFilter` rejects a match preceded by `@` — which is why the handle currently produces exactly one stray mailto span and no partial link is left behind once it is removed. Author-supplied links are unaffected: spans that were already present before linkification are excluded from the check and restored as before. A genuine address written directly after an `@` — "mail me @support@element.io" — is no longer linkified, which is the same trade-off Android already makes for web URLs.
This commit is contained in:
+9
@@ -47,6 +47,11 @@ object LinkifyHelper {
|
||||
val start = spannable.getSpanStart(urlSpan)
|
||||
val end = spannable.getSpanEnd(urlSpan)
|
||||
|
||||
if (urlSpan !in oldURLSpans && spannable.isEmailInsideFediverseHandle(urlSpan, start)) {
|
||||
spannable.removeSpan(urlSpan)
|
||||
continue
|
||||
}
|
||||
|
||||
// Try to avoid including trailing punctuation in the link.
|
||||
// Since this might fail in some edge cases, we catch the exception and just use the original end index.
|
||||
val newEnd = runCatchingExceptions {
|
||||
@@ -82,6 +87,10 @@ object LinkifyHelper {
|
||||
return spannable
|
||||
}
|
||||
|
||||
private fun Spannable.isEmailInsideFediverseHandle(urlSpan: URLSpan, start: Int): Boolean {
|
||||
return urlSpan.url.startsWith("mailto:") && start > 0 && this[start - 1] == '@'
|
||||
}
|
||||
|
||||
private fun adjustLinkifiedUrlSpanEndIndex(spannable: Spannable, start: Int, end: Int): Int {
|
||||
var end = end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user