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

[Authenticated WebView] Fix a crash related to using URLs without a scheme #13661

Merged
merged 3 commits into from
Mar 5, 2025

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Mar 5, 2025

Closes: #13660

Description

This PR fixes a crash in one of the Authenticated WebView components when passing a URL without a scheme.

Steps to reproduce

  • Either check the unit test.
  • Or use the ApiFaker to fake the product details response to return a permalink field without a scheme.

Testing information

  • Confirm the app doesn't crash in one of the two methods above.

The tests that have been performed

  • I tested just using the unit test, I think it should be enough.

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@hichamboushaba hichamboushaba added the type: crash The worst kind of bug. label Mar 5, 2025
@hichamboushaba hichamboushaba added this to the 21.8 ❄️ milestone Mar 5, 2025
Copy link

coderabbitai bot commented Mar 5, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dangermattic
Copy link
Collaborator

dangermattic commented Mar 5, 2025

1 Warning
⚠️ This PR is assigned to the milestone 21.8 ❄️. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Mar 5, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commitddbd3c4
Direct Downloadwoocommerce-wear-prototype-build-pr13661-ddbd3c4.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Mar 5, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commitddbd3c4
Direct Downloadwoocommerce-prototype-build-pr13661-ddbd3c4.apk

@codecov-commenter
Copy link

codecov-commenter commented Mar 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 38.08%. Comparing base (80bb836) to head (ddbd3c4).
Report is 4 commits behind head on release/21.8.

Additional details and impacted files
@@               Coverage Diff               @@
##             release/21.8   #13661   +/-   ##
===============================================
  Coverage           38.08%   38.08%           
- Complexity           9043     9044    +1     
===============================================
  Files                2057     2057           
  Lines              112562   112563    +1     
  Branches            14252    14252           
===============================================
+ Hits                42871    42872    +1     
  Misses              65791    65791           
  Partials             3900     3900           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@irfano irfano self-assigned this Mar 5, 2025
@irfano
Copy link
Contributor

irfano commented Mar 5, 2025

@hichamboushaba, I noticed that the default value of permalink is "".

I tested WebViewAuthenticationFlowResolver with an empty url, and it throws:
URL: ""
Error: Expected URL scheme 'http' or 'https' but no scheme was found for

Tested with example.com/path url, and it throws:
URL: "example.com/path"
Error: Expected URL scheme 'http' or 'https' but no scheme was found for exampl...

Sentry error: Expected URL scheme 'http' or 'https' but no scheme was found for
Sentry error matches the empty URL error, as there is no URL after ...found for .

I suspect the issue might be an empty permalink. In addition to this PR's solution, we could also handle empty URLs, perhaps by showing a snackbar error. WDYT?

@hichamboushaba
Copy link
Member Author

Great catch @irfano, I added the commit 0139f72 to make sure the button is not shown when the permalink is empty, let me know what you think about this solution?

@irfano
Copy link
Contributor

irfano commented Mar 5, 2025

I added the commit 0139f72 to make sure the button is not shown when the permalink is empty

This is an even better solution, thanks!

Can we still add an empty string check to WebViewAuthenticationFlowResolver? Because String.findDomain() will still crash with an empty string. It doesn't occur now, but may happen in the future. Simply adding if (url.isEmpty()) return WebViewAuthenticationFlow.None to the first line of WebViewAuthenticationFlowResolver.resolve() should work. Wdyt?

@hichamboushaba
Copy link
Member Author

Can we still add an empty string check to WebViewAuthenticationFlowResolver? Because String.findDomain() will still crash with an empty string. It doesn't occur now, but may happen in the future. Simply adding if (url.isEmpty()) return WebViewAuthenticationFlow.None to the first line of WebViewAuthenticationFlowResolver.resolve() should work. Wdyt?

Good point @irfano, but let me know what you think of my opinion before we implement it: I think it's up to the consumers to confirm they are passing non-empty URLs here, and the crash when they don't is better than having a non-ideal experience. For example in this occasion, the crash heped us idenfiy an issue that was happening for a long time where the app would open the browser using an empty URL.
WDYT?

Copy link
Contributor

@irfano irfano left a comment

Choose a reason for hiding this comment

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

It makes sense! Thanks for explaining.
Let's go with merging this. LGTM! 👍🏻

@irfano irfano merged commit a3af219 into release/21.8 Mar 5, 2025
16 checks passed
@irfano irfano deleted the issue/13660-fix-authenticated-webview-crash branch March 5, 2025 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: crash The worst kind of bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants