pwsh: encodeEnvVarsForPowerShell rejects Windows-standard env var names like ProgramFiles(x86), breaking wsh token on every pwsh block
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 84/100
Direzione di ricerca
Inizia in pkg/util/shellutil/tokenswap.go da EncodeEnvVarsForShell e encodeEnvVarsForPowerShell, quindi esamina IsValidEnvVarName in pkg/util/shellutil/shellquote.go. Verifica che il percorso PowerShell gestisca nomi come ProgramFiles(x86), mentre Bash e Fish mantengono la convalida esistente. Il lavoro è completato quando la codifica pwsh non si interrompe più con i nomi standard di Windows e continua a produrre assegnazioni valide.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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} = %sinstead 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
mainas of this report,pkg/util/shellutil/tokenswap.gois 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)"
- Lingua principale
- Go
- Stelle
- 22.3k
- Fork
- 1.1k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di wavetermdev/waveterm
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
wavetermdev/waveterm#3435 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
wavetermdev/waveterm#3432 ·
-
enhancement triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
wavetermdev/waveterm#3431 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
wavetermdev/waveterm#3428 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
wavetermdev/waveterm#3355 · 1 commento ·
Tutte le issue di wavetermdev/waveterm
Issue simili
-
kind/bug needs-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
matrixorigin/matrixone#29223 ·
-
needs-acceptance wg/data-plane-networking
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vllm-project/semantic-router#4024 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
alexgorbatchev/dotfiles#107 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100