Skip to content

[url_launcher_windows] Trim unescaped file URLs at the null terminator - #13733

Draft
ftsui wants to merge 1 commit into
flutter:mainfrom
ftsui:fix-url-launcher-file-url-trim
Draft

ftsui wants to merge 1 commit into
flutter:mainfrom
ftsui:fix-url-launcher-file-url-trim

Conversation

@ftsui

@ftsui ftsui commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

UrlUnescapeA with URL_UNESCAPE_INPLACE writes a null terminator in place without updating the length of the output std::string. Retaining the embedded null byte and trailing characters corrupts LaunchUrl error messages on percent-encoded file paths. When a file URL mixes percent-encoding with trailing multi-byte UTF-8 bytes, orphaned continuation bytes also cause Utf16FromUtf8 to fail.

Construct url_to_open from the null-terminated buffer (unescaped_url.c_str()) and add unit tests covering percent-encoded file paths and mixed percent-encoded plus raw UTF-8 paths.

Pre-Review Checklist

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

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

UrlUnescapeA with URL_UNESCAPE_INPLACE writes a null terminator in place without updating the length of the output std::string. Retaining the embedded null byte and trailing characters corrupts LaunchUrl error messages on percent-encoded file paths. When a file URL mixes percent-encoding with trailing multi-byte UTF-8 bytes, orphaned continuation bytes also cause Utf16FromUtf8 to fail.

Construct url_to_open from the null-terminated buffer (unescaped_url.c_str()) and add unit tests covering percent-encoded file paths and mixed percent-encoded plus raw UTF-8 paths.
@github-actions
github-actions Bot marked this pull request as draft November 20, 2026 02:28
@github-actions github-actions Bot added the waiting for response The Flutter team cannot make further progress on this PR until the author responds label Nov 20, 2026
@github-actions

Copy link
Copy Markdown

Hi @ftsui, thank you for your contribution!

This pull request has been converted to a draft because it does not appear to follow our pull request template:

  • Unchecked checklist items (11 of 11): All items in the Pre-Review Checklist must be completed and checked off (- [x]) before the PR can be reviewed:
    • - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
    • - [ ] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
    • - [ ] I read the [Tree Hygiene] page, which explains my responsibilities.
    • - [ ] I read and followed the [relevant style guides] and ran [the auto-formatter].
    • - [ ] I signed the [CLA].
    • - [ ] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]`
    • - [ ] I [linked to at least one issue that this PR fixes] in the description above.
    • - [ ] I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1].
    • - [ ] I updated/added any relevant documentation (doc comments with `///`).
    • - [ ] I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
    • - [ ] All existing and new tests are passing.
  • Unreplaced placeholder text: Please replace the template placeholder text at the top of the PR description with your actual description and linked issue(s):
    • *Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.*
    • *List which issues are fixed by this PR. You must list at least one issue.*

How to fix this

  1. Click the ... menu in the top-right corner of your PR description above and select Edit.
  2. Address the issues listed above. Make sure every item in the Pre-Review Checklist is present without modifications and checked off (- [x]).
  3. Save your changes, then click the "Ready for review" button at the bottom of the PR.
Click here for the raw Markdown of the Pre-Review Checklist to copy and paste
## Pre-Review Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
- [ ] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
- [ ] I read the [Tree Hygiene] page, which explains my responsibilities.
- [ ] I read and followed the [relevant style guides] and ran [the auto-formatter].
- [ ] I signed the [CLA].
- [ ] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]`
- [ ] I [linked to at least one issue that this PR fixes] in the description above.
- [ ] I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1].
- [ ] I updated/added any relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
- [ ] All existing and new tests are passing.

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

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.

<!-- Links -->
[Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
[AI contribution guidelines]: https://github.com/flutter/flutter/blob/master/CONTRIBUTING.ai.md#pull-requests
[Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style
[the auto-formatter]: https://github.com/flutter/packages/blob/main/script/tool/README.md#format-code
[CLA]: https://cla.developers.google.com/
[Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
[linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview
[the version and CHANGELOG instructions]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version-and-changelog-updates
[semantic versioning]: https://dart.dev/tools/pub/versioning#semantic-versions
[repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style
[test exemption]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates url_launcher_windows to version 3.1.7, addressing an issue where in-place unescaping of file: URLs retains trailing bytes by assigning url_to_open to unescaped_url.c_str(). It also adds unit tests to verify this behavior. The review feedback suggests optimizing the string assignment by resizing and moving unescaped_url to avoid an unnecessary copy, and using universal character names instead of hex escape sequences in wide string literals to prevent greedy parsing in tests.

url_to_open = unescaped_url;
// UrlUnescapeA with URL_UNESCAPE_INPLACE null-terminates the buffer in
// place without updating unescaped_len or std::string's length.
url_to_open = unescaped_url.c_str();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Instead of copying the string buffer by assigning url_to_open = unescaped_url.c_str();, you can resize unescaped_url to its actual null-terminated length and then move it into url_to_open. This avoids an unnecessary string copy and allocation.

Suggested change
url_to_open = unescaped_url.c_str();
unescaped_url.resize(std::char_traits<char>::length(unescaped_url.c_str()));
url_to_open = std::move(unescaped_url);


EXPECT_CALL(*system,
ShellExecuteW(_, StrEq(L"open"),
StrEq(L"file:///C:/Quick Share/\x00e9"), _, _, _))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using hex escape sequences like \x00e9 in wide string literals can be greedy and consume subsequent valid hex characters if the string is modified in the future. It is safer and more idiomatic to use universal character names (e.g., \u00e9) which are always exactly 4 hex digits.

Suggested change
StrEq(L"file:///C:/Quick Share/\x00e9"), _, _, _))
StrEq(L"file:///C:/Quick Share/\u00e9"), _, _, _))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: url_launcher platform-windows waiting for response The Flutter team cannot make further progress on this PR until the author responds

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant