Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

pwsh: encodeEnvVarsForPowerShell rejects Windows-standard env var names like ProgramFiles(x86), breaking wsh token on every pwsh block

オープン 初心者向け
#3,481 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@vortsghost2025 がすでに取り組んでいます。

2026年9月9日 から。

  • #3497 @vortsghost2025 による — マージされずにクローズ
  • #3498 @vortsghost2025 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, powershell
領域
cli, tooling

調査の方向性

pkg/util/shellutil/tokenswap.go の EncodeEnvVarsForShell と encodeEnvVarsForPowerShell から始め、次に pkg/util/shellutil/shellquote.go の IsValidEnvVarName を確認します。PowerShell のパスが ProgramFiles(x86) のような名前を処理し、Bash と Fish では既存の検証が維持されることを確認してください。pwsh のエンコードが Windows 標準の名前で中断せず、引き続き有効な代入を生成すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Description

encodeEnvVarsForPowerShell in pkg/util/shellutil/tokenswap.go validates every environment variable name against the strict POSIX-identifier regex ^[A-Za-z_][A-Za-z0-9_]*$ (IsValidEnvVarName in pkg/util/shellutil/shellquote.go), and this validation is applied unconditionally to ALL shells in EncodeEnvVarsForShell, including pwsh.

Windows always defines environment variables containing parentheses, e.g. ProgramFiles(x86) and CommonProgramFiles(x86). These names fail the regex, so encodeEnvVarsForPowerShell returns:

invalid env var name: "ProgramFiles(x86)"

EncodeEnvVarsForShell propagates this as a hard error, which aborts the entire token exchange, not just the one offending variable.

Why this matters

This is not a cosmetic edge case, it fires on essentially every PowerShell block launch on Windows. Wave's own bundled pwsh shell-integration script (wavepwsh.ps1, generated for the pwsh shell type) runs:

wsh token $env:WAVETERM_SWAPTOKEN pwsh 2>$null

The 2>$null silently swallows the error, so the failure is invisible in normal use, but the entire env-var/init-script exchange for that block never runs.

Root cause

$env:ProgramFiles(x86) = "..." is invalid PowerShell syntax (parens are parsed as a command invocation), so the strict validator was presumably written to avoid emitting that. But PowerShell has a second, valid assignment form for exactly this case:

${env:ProgramFiles(x86)} = "..."

The ${env:NAME} delimited form tolerates parentheses (and most other characters) in the variable name. The validator doesn't need to reject these names for PowerShell at all, it just needs to emit the delimited form instead of the bare $env:NAME form.

Suggested fix

Scope the fix to encodeEnvVarsForPowerShell only (leave encodeEnvVarsForBash / encodeEnvVarsForFish untouched, the POSIX identifier rule is correct there):

  • Emit ${env:%s} = %s instead of $env:%s = %s.
  • Only reject a name if it's structurally impossible to express in that form (empty, or contains a literal }), rather than requiring a POSIX identifier.
Environment
  • Wave Terminal / wsh version: v0.14.5 (also present in current main as of this report, pkg/util/shellutil/tokenswap.go is unchanged on that path)
  • OS: Windows 11
  • Shell: pwsh (PowerShell 7)
Repro
package main

import (
	"fmt"
	"github.com/wavetermdev/waveterm/pkg/util/shellutil"
)

func main() {
	env := map[string]string{"ProgramFiles(x86)": `C:\Program Files (x86)`}
	_, err := shellutil.EncodeEnvVarsForShell("pwsh", env)
	fmt.Println(err) // invalid env var name: "ProgramFiles(x86)"
}

Or from a shell with any real Windows environment:

wsh token <valid-swap-token> pwsh
# Error: error encoding env vars: invalid env var name: "ProgramFiles(x86)"
主要言語
Go
スター
22.4k
フォーク
1.1k
平均マージ
3日 13時間
マージ済み PR(30日)
13

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

wavetermdev/waveterm のほかの issue

wavetermdev/waveterm の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。