Skip to content

[url_launcher] Decode file URLs before passing it to ShellExecuteW #7774

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

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

ftsui
Copy link
Contributor

@ftsui ftsui commented Oct 3, 2024

  • ShellExecuteW does not handle file: urls that contain %-encoded UTF-8 strings correctly. %-encoded ASCII
    strings are handled correctly, as are file "urls" that contain Unicode strings in its path component.
  • This change perform URL decode on file: urls before passing to ShellExecuteW.

Fixes flutter/flutter#156790

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@ftsui ftsui requested a review from cbracken as a code owner October 3, 2024 00:30
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@ftsui ftsui changed the title Decode URL before passing it to ShellExecuteW. [url_launcher] Decode URL before passing it to ShellExecuteW. Oct 3, 2024
@ftsui ftsui force-pushed the urllauncher branch 7 times, most recently from cf02161 to d5d8423 Compare October 3, 2024 19:13
@stuartmorgan-g
Copy link
Contributor

Thanks for the contribution! Since the checklist isn't complete, I'm assuming this is a work in progress, and marking as a Draft accordingly. Once you've completed all of the steps, please mark it as ready for review.

It also appears that this PR assumes that url_launcher is only used for file: URLs. It's intended for use with any URL, and is very frequently used with schemes like https and mailto; a change that breaks those use cases would not be accepted.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft October 5, 2024 20:59
@ftsui ftsui force-pushed the urllauncher branch 3 times, most recently from a60971f to abd0f7b Compare October 14, 2024 18:52
- ShellExecuteW does not handle file: urls that contain %-encoded UTF-8
  strings correctly.  %-encoded ASCII strings are handled correctly, as
  are file "urls" that contain Unicode strings in its path component.
- This change perform URL decode on file: urls before passing to
  ShellExecuteW.
@ftsui ftsui marked this pull request as ready for review October 15, 2024 15:58
@ftsui ftsui changed the title [url_launcher] Decode URL before passing it to ShellExecuteW. [url_launcher] Decode file URLs before passing it to ShellExecuteW Oct 15, 2024
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM, @cbracken for secondary review.

(Longer term we may need to revisit this logic; it's not at all clear that we are using open correctly current even though it mostly seems to work. The docs say "The item can be a file or folder", and even with this change we are passing a file URL rather than path, which may not be right. And it's not clear whether open is supposed to even work at all for other kinds of URLs, even though it apparently does.)

@ftsui
Copy link
Contributor Author

ftsui commented Oct 17, 2024

My guess would be that file: is being handled by ShellExecute as a file moniker (which happens to have a similar syntax, but without URL encoding). That might also explain starting the image editor instead of a browser when passed an image file. It would be a somewhat unfortunate change in behavior if this were to be changed to pass all URLs to the browser.

@stuartmorgan-g
Copy link
Contributor

stuartmorgan-g commented Oct 17, 2024

It would be a somewhat unfortunate change in behavior if this were to be changed to pass all URLs to the browser.

That's definitely an anti-goal. What we want is for the OS to determine the best handler for any given URL and pass it to that; that's explicitly what the underlying APIs used by all the other platform implementations of url_launcher do. It seems like open is doing that in practice (at least mostly) on Windows, but it doesn't seem like that's documented behavior so ideally we'd find something that explicitly is documented to do the thing we want (if there is such a thing on Windows).

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

LGTM stamp from a Japanese personal seal

lgtm. There's a joke to be made somewhere about 管理ing all of my various 家s, but I'm not sure I'm clever enough to make it.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 17, 2024
@auto-submit auto-submit bot merged commit c23f4be into flutter:main Oct 17, 2024
76 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 18, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 18, 2024
flutter/packages@5582669...2a1c477

2024-10-18 [email protected] [camera_android] Convert Dart to native calls to use Pigeon (flutter/packages#7874)
2024-10-17 [email protected] [url_launcher] Decode file URLs before passing it to ShellExecuteW (flutter/packages#7774)
2024-10-17 [email protected] [in_app_purchase_storekit] Add support for purchase and transactions (flutter/packages#7887)
2024-10-17 [email protected] [interactive_media_ads] Adds internal wrapper for iOS native `IMACompanionAd` (flutter/packages#7873)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: url_launcher platform-windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[url_launcher] Windows plugin is unable to correctly open file URLs with non-ASCII characters
3 participants