Skip to content

Fix: Un-escape the value before setting LANG#41103

Open
chemwolf6922 wants to merge 1 commit into
masterfrom
user/chemwolf6922/fix-wrong-LANG-parsing
Open

Fix: Un-escape the value before setting LANG#41103
chemwolf6922 wants to merge 1 commit into
masterfrom
user/chemwolf6922/fix-wrong-LANG-parsing

Conversation

@chemwolf6922

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

The value in locale files could be shell escaped. The old parsing logic sets the string directly. Which could set LANG to a wrong value like "en_US.UTF-8".

This PR un-escapes the value string before setting it to the env LANG.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Update tests:
SimpleTests::SimpleTests::StringHelpers
UnitTests::UnitTests::ConfigUpdateLanguage

Copilot AI review requested due to automatic review settings July 17, 2026 05:11
@chemwolf6922
chemwolf6922 requested a review from a team as a code owner July 17, 2026 05:11
@chemwolf6922 chemwolf6922 linked an issue Jul 17, 2026 that may be closed by this pull request
2 tasks

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 incorrect LANG values when distro locale files store the value with shell-style escaping/quoting (e.g., LANG="en_US.UTF-8"). It adds shared string helpers to trim and unescape shell-escaped strings, then uses them when parsing locale configuration in the Linux init path, with accompanying unit test updates.

Changes:

  • Add wsl::shared::string::Trim() and wsl::shared::string::UnescapeShell() helpers in stringshared.h.
  • Unescape/trim the locale-file LANG value before calling Environment.AddVariable() in src/linux/init/config.cpp.
  • Update/extend unit tests to cover quoted locale values and new string helper behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/windows/UnitTests.cpp Adjusts language config test to validate quoted LANG values using printenv.
test/windows/SimpleTests.cpp Adds coverage for new Trim/UnescapeShell helpers.
src/shared/inc/stringshared.h Introduces Trim and UnescapeShell utilities for shared string handling.
src/linux/init/config.cpp Applies trim + shell-unescape to locale-file LANG prior to setting the environment.

Comment thread src/shared/inc/stringshared.h
}

template <typename TChar>
inline std::basic_string<TChar> UnescapeShell(const std::basic_string<TChar>& input)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On bad input the original string is returned, I guess that's intentional?

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.

Cannot run PowerShell 7.7.0 Preview 2 on AlmaLinux 8 with WSL 2.9.4.0

3 participants