Skip to content
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

Ask the user to confirm urls which contain unicode direction overrides #6164

Merged
merged 3 commits into from
May 30, 2022

Conversation

ouchadam
Copy link
Contributor

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Checks for the presence of Right to Left unicode directional overrides when tapping on a URL, if one is found we'll show the user the URL with the overrides disabled and ask them to confirm they want to continue.

Motivation and context

Fixes #6163

Newer versions of Android (31+) seemingly handle the oddness out of the box by avoiding marking the URLs as clickable links, however previous versions will still attempt to link out to them, although the formatting is often broken.

Screenshots / GIFs

BEFORE AFTER
2022-05-26T10:26:35,157524612+01:00 Screenshot_20220526_113846

Tests

  • Using Element web /devtools construct and post a link containing a RtL override \u202E
  • Using an Android 25 device view and tap the link
  • Notice a popup informing the user that the URL may not be what they expect

Tested devices

  • Physical
  • Emulator
  • OS version(s): 21, 25, 28, 31

@@ -1922,30 +1925,36 @@ class TimelineFragment @Inject constructor(
}
})
if (!isManaged) {
if (title.isValidUrl() && url.isValidUrl() && URL(title).host != URL(url).host) {
MaterialAlertDialogBuilder(requireActivity(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_NegativeDestructive)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the dialog displaying has been extracted to its own function

openUrlInExternalBrowser(requireContext(), url)
when {
url.containsRtLOverride() || (title.isValidUrl() && url.isValidUrl() && URL(title).host != URL(url).host) -> {
displayUrlConfirmationDialog(title.ensureEndsLeftToRight(), url.filterDirectionOverrides())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to ensure the text returns to LtR at the end with title.ensureEndsLeftToRight(), otherwise the override character will cause the rest of the string resource to also become inverted

WITHOUT LTR OVERRIDE
Screenshot_20220526_124304

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url.filterDirectionOverrides() will also be used to open the url, if the user accepts. Will it work fine? Or considerer adding url as a new param.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! no it should be a separate parameter, will update 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

github-actions bot commented May 26, 2022

Unit Test Results

128 files  +  4  128 suites  +4   2m 33s ⏱️ +16s
224 tests +  4  224 ✔️ +  4  0 💤 ±0  0 ±0 
742 runs  +16  742 ✔️ +16  0 💤 ±0  0 ±0 

Results for commit 67f1929. ± Comparison against base commit 0675b7c.

♻️ This comment has been updated with latest results.

@ouchadam ouchadam requested review from a team, ganfra and Florian14 and removed request for a team May 26, 2022 12:08
@ouchadam ouchadam added the Z-NextRelease For issues and PRs which should be included in the NextRelease. label May 27, 2022
Copy link
Member

@BillCarsonFr BillCarsonFr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
The existing case was working finally? (you told me it was not the case)

openUrlInExternalBrowser(requireContext(), url)
when {
url.containsRtLOverride() || (title.isValidUrl() && url.isValidUrl() && URL(title).host != URL(url).host) -> {
displayUrlConfirmationDialog(title.ensureEndsLeftToRight(), url.filterDirectionOverrides())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url.filterDirectionOverrides() will also be used to open the url, if the user accepts. Will it work fine? Or considerer adding url as a new param.

// Open in external browser, in a new Tab
openUrlInExternalBrowser(requireContext(), url)
when {
url.containsRtLOverride() || (title.isValidUrl() && url.isValidUrl() && URL(title).host != URL(url).host) -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe split into 2 cases rather than using || for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ouchadam
Copy link
Contributor Author

Thanks. The existing case was working finally? (you told me it was not the case)

kind of~ after looking into the logic, the url detection only takes into account urls with a protocol, for example [google.com](https://youtube.com) will skip the check

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

@bmarty bmarty merged commit ab651cb into develop May 30, 2022
@bmarty bmarty deleted the bug/adm/link-checking branch May 30, 2022 12:07
@github-actions
Copy link

Matrix SDK

Integration Tests Results:

  • [org.matrix.android.sdk.session]
    = passed=20 failures=0 errors=0 skipped=3
  • [org.matrix.android.sdk.account]
    = passed=3 failures=0 errors=0 skipped=2
  • [org.matrix.android.sdk.internal]
    = passed=27 failures=1 errors=0 skipped=1
  • [org.matrix.android.sdk.ordering]
    = passed=16 failures=0 errors=0 skipped=0
  • [org.matrix.android.sdk.PermalinkParserTest]
    = passed=2 failures=0 errors=0 skipped=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-NextRelease For issues and PRs which should be included in the NextRelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ask for confirmation when a url with unicode directional characters are present
3 participants