# Fix Windows task path handling for worktree variables with spaces \(\#55727\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/01448f565e52f5b370b40718663e9649b16990f0)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 01448f565e52f5b370b40718663e9649b16990f0

Requested commit: 01448f565e52f5b370b40718663e9649b16990f0

Commit: 01448f565e52f5b370b40718663e9649b16990f0

Tree: 19663c449f5aa4943089d2b52286e8e6bd0a1a9b

Author: Indy Fu

Committer: GitHub

## Message

```
Fix Windows task path handling for worktree variables with spaces (#55727)

## Summary
Fixes task variable resolution and Windows shell argument handling when
`$ZED_WORKTREE_ROOT` contains spaces or when tasks are spawned while the
global `tasks.json` buffer is focused.

## Problem
`$ZED_WORKTREE_ROOT` could resolve from the active editor item even when
that item was outside every visible project worktree, such as the global
`tasks.json` file under the Zed config directory. On Windows, paths with
spaces also need to remain one logical argument when terminal shell
commands are constructed.

## Changes
- Only let the active editor item provide the active task context when
it belongs to a visible project worktree.
- Fall back to the selected or first visible project worktree when the
active editor item is external/global.
- Preserve project-file-specific task variables for normal project
buffers.
- Add regression coverage for `$ZED_WORKTREE_ROOT` in `args` and `cwd`
with synthetic Windows-style paths containing spaces.
- Add regression coverage for PowerShell and cmd shell command
construction so a spaced path remains quoted as one shell argument.

## Testing
Ran on Windows with Rust 1.95.0, Visual Studio Build Tools 2022, and
Windows SDK 10.0.26100.0:

- `cargo fmt --all --check`
- `cargo test -p util
shell_builder::test::windows_powershell_preserves_spaced_arg_as_single_shell_argument
-- --exact`
- `cargo test -p util
shell_builder::test::windows_cmd_preserves_spaced_arg_as_single_shell_argument
-- --exact`
- `cargo test -p task
task_template::tests::test_worktree_root_with_spaces_stays_atomic_in_args_and_cwd
-- --exact`
- `cargo test -p tasks_ui
tests::test_non_project_active_editor_uses_visible_worktree_context --
--exact`
- `cargo test -p task`
- `cargo test -p tasks_ui`
- `cargo test -p workspace`

Release Notes:

- Fix Windows task path handling for worktree variables with spaces
- [GPUI] N/A

Co-authored-by: Chris Biscardi <chris@christopherbiscardi.com>
```

## Parents

- [c982733897f7f8dcde4a69938bd62e35f445a756](https://git.cafe/gitcafe/zed/commit/c982733897f7f8dcde4a69938bd62e35f445a756?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/01448f565e52f5b370b40718663e9649b16990f0?format=markdown)
