Skip to content

fix: handle non-ASCII characters in PowerShell paths - #7793

Merged
JanDeDobbeleer merged 1 commit into
nextfrom
claude/powershell-utf8-encoding-ati5z1
Aug 12, 2026
Merged

fix: handle non-ASCII characters in PowerShell paths#7793
JanDeDobbeleer merged 1 commit into
nextfrom
claude/powershell-utf8-encoding-ati5z1

Conversation

@JanDeDobbeleer

Copy link
Copy Markdown
Owner

Prerequisites

  • I have read and understood the contributing guide.
  • The commit message follows the conventional commits guidelines.
  • Tests for the changes have been added (for bug fixes / features).
  • Docs have been added/updated (for bug fixes / features).

Description

PowerShell on Windows decodes native command output using [Console]::OutputEncoding, which defaults to the legacy OEM code page. This causes multi-byte UTF-8 sequences in stdout to be mangled before the init script can process them, breaking paths containing non-ASCII characters.

This fix addresses the issue by:

  1. Splitting quotePwshOrElvishStr into separate functions: Created quotePwshStr() for PowerShell and quoteElvishStr() for Elvish, since they have different quoting requirements.

  2. Encoding non-ASCII characters as [char] expressions: The new quotePwshStr() function detects non-ASCII runes and emits them as PowerShell character expressions (e.g., [char]0xB2 for ², [char]::ConvertFromUtf32(0x1F4C1) for 📁). This keeps the emitted code pure ASCII, which survives any code page decoding.

  3. Using expandable strings for concatenation: Non-ASCII characters are wrapped in "$(...)" syntax to ensure proper string concatenation semantics in PowerShell.

  4. Updated all call sites: Replaced quotePwshOrElvishStr() calls with the appropriate shell-specific function in init.go.

Test Plan

  • Added comprehensive unit tests for quotePwshStr() covering ASCII paths, paths with single quotes, and paths with various non-ASCII characters (U+00B2, U+00D8, U+1F4C1)
  • Added new test TestSessionScriptPwshIsPureASCII() that verifies the entire session script output contains only ASCII bytes, even when config paths contain non-ASCII characters
  • Existing tests for Elvish quoting continue to pass with the new quoteElvishStr() function

https://claude.ai/code/session_01BCNz9G4sSmwRixkjVodcWo

@cursor

cursor Bot commented Aug 12, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@github-actions

Copy link
Copy Markdown

📦 Release binary size report

Compares this PR's release-equivalent build against the latest published release, per OS (amd64).

OS Baseline This PR Delta
darwin 13.78 MB 13.78 MB +0.0 KB (+0%)
linux 13.45 MB 13.45 MB +0.0 KB (+0%)
windows 14.01 MB 13.97 MB -38.8 KB (-0.27%)

🎉 Binary size shrank on at least one platform.

@JanDeDobbeleer
JanDeDobbeleer changed the base branch from main to next August 12, 2026 19:16
PowerShell decodes native command stdout using [Console]::OutputEncoding,
which defaults to the legacy OEM code page on Windows. When a path in the
init bootstrap contains non-ASCII characters (e.g. a ² in the username),
the UTF-8 bytes are mangled before the init script can run, breaking
initialization with 'term is not recognized' errors.

Quote pwsh strings containing non-ASCII runes as expandable string
expressions built from [char] casts so everything written to stdout, and
to the on-disk init script, is pure ASCII, which survives every code
page. Elvish keeps the previous plain single-quote behavior via its own
quoting function.

Validated against pwsh 7.4.6 in every injection context: env var
assignment, the call operator, Invoke-Expression, argument-mode
--config= tokens, and the omp.ps1 executable assignment.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCNz9G4sSmwRixkjVodcWo
@JanDeDobbeleer
JanDeDobbeleer force-pushed the claude/powershell-utf8-encoding-ati5z1 branch from 5abe227 to 648b291 Compare August 12, 2026 20:45
@JanDeDobbeleer
JanDeDobbeleer merged commit e458c6e into main Aug 12, 2026
14 of 15 checks passed
@JanDeDobbeleer
JanDeDobbeleer deleted the claude/powershell-utf8-encoding-ati5z1 branch August 12, 2026 20:58
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.

2 participants