Repository navigation
Conversation
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.
|
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:
How to fix this
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
| 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"), _, _, _)) |
There was a problem hiding this comment.
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.
| StrEq(L"file:///C:/Quick Share/\x00e9"), _, _, _)) | |
| StrEq(L"file:///C:/Quick Share/\u00e9"), _, _, _)) |
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
[shared_preferences]///).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-assistbot 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
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