Skip to content

Fix incorrect string -> wstring conversion, causing utf16 corruption - #41406

Merged
Blue (OneBlue) merged 1 commit into
masterfrom
user/oneblue/fix-string-corruption
Aug 21, 2026
Merged

Fix incorrect string -> wstring conversion, causing utf16 corruption#41406
Blue (OneBlue) merged 1 commit into
masterfrom
user/oneblue/fix-string-corruption

Conversation

@OneBlue

Copy link
Copy Markdown
Collaborator

Summary of the Pull Request

The issue was using std::format_to with a narrow string, which would actually convert the string back to utf8, and writing utf8 bytes on a wide string, causing corruption

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI lite review requested due to automatic review settings August 21, 2026 01:12
@OneBlue
Blue (OneBlue) requested review from a team as code owners August 21, 2026 01:12

Copilot AI 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.

Pull request overview

This PR fixes UTF-16 corruption when formatting UTF-8 char strings into wide (wchar_t) formatted output by ensuring the wide-formatting formatter specializations use wide format strings.

Changes:

  • Fix std::formatter<... , wchar_t> specializations in stringshared.h to use L"{}" (wide) instead of "{}" (narrow) when writing to a wide format context.
  • Add a Windows unit test validating std::format(L"{}", std::string) produces the expected wide string for UTF-8 input.
  • Add a WSLC E2E test that exercises Unicode build output and asserts the expected Unicode substring is present.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp Adds an E2E test that validates Unicode output from wslc build is not corrupted.
test/windows/StringUnitTests.cpp Adds a unit test covering UTF-8 std::string → wide std::format behavior.
src/shared/inc/stringshared.h Fixes wide-context std::formatter implementations to format using wide format strings, preventing UTF-16 corruption.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@OneBlue
Blue (OneBlue) merged commit aeacef1 into master Aug 21, 2026
12 checks passed
@OneBlue
Blue (OneBlue) deleted the user/oneblue/fix-string-corruption branch August 21, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants