Skip to content

Fix PowerShell encoding for Windows environment variable names - #3498

Open
vortsghost2025 wants to merge 1 commit into
wavetermdev:mainfrom
vortsghost2025:contrib/wave-upstream
Open

Fix PowerShell encoding for Windows environment variable names#3498
vortsghost2025 wants to merge 1 commit into
wavetermdev:mainfrom
vortsghost2025:contrib/wave-upstream

Conversation

@vortsghost2025

Copy link
Copy Markdown

Summary

Fixes #3481.

  • Emit braced ${env:NAME} assignments for PowerShell environment variables.
  • Accept Windows-standard names such as ProgramFiles(x86) and CommonProgramFiles(x86).
  • Reject empty names and names containing }.
  • Preserve Bash/fish validation and add coverage for ordinary PATH plus Windows names.

Test plan

  • go test ./pkg/util/shellutil -count=1
  • go test ./pkg/util/shellutil -run 'TestEncodeEnvVarsForPowerShell' -count=1
  • PowerShell 7.6.5 runtime validation

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 21bb27a7-e431-4f32-b4fe-b03c09c14b6a

📥 Commits

Reviewing files that changed from the base of the PR and between a4447c1 and 853897b.

📒 Files selected for processing (2)
  • pkg/util/shellutil/tokenswap.go
  • pkg/util/shellutil/tokenswap_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

PowerShell environment variable encoding now accepts Windows-standard names such as ProgramFiles(x86) and CommonProgramFiles(x86). It emits assignments with ${env:NAME} syntax. It rejects empty names and names containing }. Table-driven tests cover valid output and rejected names.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 85389

PowerShell environment exchanges now support standard Windows variable names while rejecting names that cannot be represented safely. The focused encoding and validation coverage indicates no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: fixing PowerShell encoding for Windows environment variable names.
Description check ✅ Passed The description directly explains the PowerShell encoding fix, validation changes, preserved shell behavior, and test coverage.
Linked Issues check ✅ Passed The changes satisfy issue #3481 by using braced PowerShell assignments, accepting names such as ProgramFiles(x86), rejecting empty or closing-brace names, and preserving Bash and fish validation.
Out of Scope Changes check ✅ Passed The changes are limited to PowerShell encoding and related tests. No unrelated code changes are identified.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 853897bfc2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if !IsValidEnvVarName(k) {
// PowerShell's braced environment-variable syntax supports Windows names
// such as ProgramFiles(x86), but a closing brace cannot be represented.
if k == "" || strings.Contains(k, "}") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject or escape backticks in PowerShell variable names

When the environment contains an otherwise legal OS variable name with a backtick, such as FOO\``, this validation accepts it and interpolates the name directly into ${env:...}`. The PowerShell variable-name rules identify the backtick as an escape character excluded from braced variable names; in particular, a trailing backtick escapes the generated closing brace, making the token script unparsable and preventing shell initialization. Reject backticks here or escape them correctly before interpolation.

Useful? React with 👍 / 👎.

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.

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

1 participant