-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try avoiding trailing punctuation inside linkified URLs #4214
base: develop
Are you sure you want to change the base?
Try avoiding trailing punctuation inside linkified URLs #4214
Conversation
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
@Composable | ||
internal fun ClickableLinkTextWithParenthesisPreview() = ElementThemedPreview { | ||
ClickableLinkText( | ||
annotatedString = AnnotatedString("Does this work (url: github.com/element-hq/element-x-android/README?)?!.", ParagraphStyle()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add exemple where parenthesis is part of the url?
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4214 +/- ##
===========================================
- Coverage 80.24% 80.23% -0.01%
===========================================
Files 2042 2043 +1
Lines 54079 54104 +25
Branches 6569 6580 +11
===========================================
+ Hits 43393 43412 +19
- Misses 8414 8415 +1
- Partials 2272 2277 +5 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have tested and the target link need to be updated as well.
end = adjustEndIndex(spannable, start, end) | ||
}.onFailure { | ||
Timber.e(it, "Failed to adjust end index for link span") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is adjusting the end
of the span, so this is fixing the rendering issue, but it does this affect the URL itself, i.e. the target of the link.
I think the line annotation = span.url,
below needs to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the Event renderer use ClickableLinkText
? It seems it's not the case 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh damn, it used to use it, that's why I tried fixing it here. I'll move the code where it belongs 🥲 .
9ef2d3f
to
323c811
Compare
Quality Gate passedIssues Measures |
This should be ready to review again: it's now affecting the intended texts (🤦 ) and has some extra unit tests for the new component. |
Content
When an URL is linkified automatically by
LinkifyCompat
, try removing any trailing punctuation and other mismatched symbols from the link span.This solution is not great and might fail in some cases, but it should cover the most common ones, since it seems like a 'smart' linkification library is hard to find as a replacement.
Motivation and context
It turns out the
Linkify
component from Google isn't as smart as we thought: as soon as a/
char is found inside the URL, it'll greedily fetch as much text as possible. This is probably because a different regex is used internally than for a simple domain.Should fix #4208.
Screenshots / GIFs
Tests
You can play with the
ClickableLinkTextWithParenthesisPreview
composable preview, or send messages with URLs and problematic formats to be linkified.Tested devices
Checklist