Skip to content

util: Prevent panic when parsing a malformed shell variable - #63446

Open
39ali wants to merge 1 commit into
zed-industries:mainfrom
39ali:shell-fix
Open

util: Prevent panic when parsing a malformed shell variable#63446
39ali wants to merge 1 commit into
zed-industries:mainfrom
39ali:shell-fix

Conversation

@39ali

@39ali 39ali commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Objective

to_cmd_variable and to_powershell_variable removed the last byte of a
${...} argument assuming it was the closing brace, without checking one was
there

// If the input starts with "${", remove the trailing "}"
format!("$env:{}", &var_str[..var_str.len() - 1])

Solution

Use strip_suffix('}') and pass the input through when it isn't a variable reference

Testing

added tests to cover this

To reproduce on Windows, add a context server with a malformed argument to settings.json:


"context_servers": {
  "crash-repro": {
    "command": "does-not-matter",
    "args": ["${"]
  }
}
} 

Opening the agent panel and zed will crash

Release Notes:

  • Fixed a panic when converting a malformed ${ shell variable reference on Windows

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Aug 30, 2026
@ChristopherBiscardi ChristopherBiscardi added the area:integrations/terminal Feedback for terminal integration, shell commands, etc label Aug 31, 2026
@SomeoneToIgnore SomeoneToIgnore self-assigned this Aug 31, 2026

@SomeoneToIgnore SomeoneToIgnore 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.

Thanks, one nit to fix and we're ready to merge.

Comment thread crates/util/src/shell.rs
// If the input starts with "${", remove the trailing "}"
format!("%{}%", &var_str[..var_str.len() - 1])
} else {
match var_str.strip_suffix('}') {
// `${SOME_VAR:-SOME_DEFAULT}`, we currently do not handle this situation,

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.

This comment belongs to input.into branch, let's keep them together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:integrations/terminal Feedback for terminal integration, shell commands, etc cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants