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

fix(message): fix in-message embedded link validator (WPB-3554) #2088

Merged
merged 2 commits into from
Aug 11, 2023

Conversation

mchenani
Copy link
Contributor


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like SQPIT-764
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?

Update the logic to check the embedded link in a message:
1- Show a visit link confirmation dialog when the user click on an embedded link
2- if the link starts with schema [anyString]://[anystring] we don't modify the link
ELSE -> add https:// to the link/text

Testing

Unit tests added

Test Coverage (Optional)

  • I have added automated test to this contribution

How to Test

Send a message with any combination of links you can imagine:
1- the visit link dialog, always must be appear
2- if the link misses the schema the shown link in the above dialog must start with https
3- if the link starts with schema, the shown link in the dialog must be the same as you posted
4- the app must not crash in any cases


References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 11, 2023

Test Results

539 tests   538 ✔️  22s ⏱️
  77 suites      1 💤
  77 files        0

Results for commit c240c98.

♻️ This comment has been updated with latest results.

@AndroidBob
Copy link
Collaborator

Build 1025 failed.

return if (containsSchema(normalizedUrl)) {
normalizedUrl
} else {
"https://$normalizedUrl"
Copy link
Member

@MohamadJaara MohamadJaara Aug 11, 2023

Choose a reason for hiding this comment

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

question: if the link already have something like, "/google.com" then it will turn into "https:///google.com" and it will fail to open, do we need to care about those edge cases ?

Copy link
Contributor

Choose a reason for hiding this comment

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

/google.com is not a URL

Copy link
Contributor

Choose a reason for hiding this comment

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

but what if we send [google](/google.com) then it will go https:///google.com as @MohamadJaara mentioned, no? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I'd blame whoever pasted the invalid URI there to be honest 😄.

Would be a nice to have for the rare cases where people mistype that hard, but not sure if worth the effort

@tmspzz tmspzz requested review from a team, yamilmedina, alexandreferris, borichellow, MohamadJaara, saleniuk and vitorhugods and removed request for a team August 11, 2023 10:11
Copy link
Contributor

@alexandreferris alexandreferris left a comment

Choose a reason for hiding this comment

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

Just some questions 🤔

return if (containsSchema(normalizedUrl)) {
normalizedUrl
} else {
"https://$normalizedUrl"
Copy link
Contributor

Choose a reason for hiding this comment

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

but what if we send [google](/google.com) then it will go https:///google.com as @MohamadJaara mentioned, no? 🤔

Comment on lines +23 to +25
val regexPattern = Regex(".+://.+")

return regexPattern.matches(url)
Copy link
Member

@vitorhugods vitorhugods Aug 11, 2023

Choose a reason for hiding this comment

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

Suggestion: leverage already existing functions in the JVM.

Suggested change
val regexPattern = Regex(".+://.+")
return regexPattern.matches(url)
return try {
URI.create(string).schema != null
} catch (iae: IllegalArgumentException) {
false // invalid URI
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this only validates against valid and known schemes, it's not passing against unknown schemes.

Copy link
Member

@vitorhugods vitorhugods Aug 11, 2023

Choose a reason for hiding this comment

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

@mchenani how so?

image image

@github-actions
Copy link
Contributor

APKs built during tests are available here. Scroll down to Artifacts!

Copy link
Contributor

@borichellow borichellow left a comment

Choose a reason for hiding this comment

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

have nothing to add to the existed comments :)

@AndroidBob
Copy link
Collaborator

Build 1028 succeeded.

The build produced the following APK's:

@mchenani mchenani merged commit dd4c9d3 into release/candidate Aug 11, 2023
10 checks passed
@mchenani mchenani deleted the rc/fix/in_message_embedded_link_validator branch August 11, 2023 11:03
@echoes-hq echoes-hq bot added the echoes: product-roadmap Work aligned with the customer-announced roadmap, targeting a specific release date. label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: product-roadmap Work aligned with the customer-announced roadmap, targeting a specific release date. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants