# path: Normalize Windows paths independently of the host platform \(\#61374\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 2610332077ee05f4c9e2e1caa7d80a4dcde3deb6

Requested commit: 2610332077ee05f4c9e2e1caa7d80a4dcde3deb6

Commit: 2610332077ee05f4c9e2e1caa7d80a4dcde3deb6

Tree: cd6fc230dd96045d5f10f1d7444ca546be04abf7

Author: Xin Zhao

Committer: GitHub

## Message

```
path: Normalize Windows paths independently of the host platform (#61374)

# Objective

Zed's `PathStyle` is designed to handle paths across platforms. Its
behavior should depend only on the selected path style, not on the
platform where Zed is running. This is essential for remote development,
where the local and remote platforms may differ.

While fixing bugs involving Windows remote targets, I found that
`PathStyle::normalize` does not behave consistently across host
platforms. For `PathStyle::Windows`, it delegates to
`crate::normalize_path`:


https://github.com/zed-industries/zed/blob/914e1c9873b6b85bfeedc5b58e8270885bdd532e/crates/path/src/path.rs#L237-L263

That function uses `Path::components()`, which interprets paths
according to the host platform. As a result, when Zed runs on a
Unix-like system and connects to a Windows remote, something maybe wrong
here.

`PathStyle::normalize` should instead interpret paths according to the
selected `PathStyle`, independently of the host platform.

## Solution

Implement Windows path normalization directly in `PathStyle::normalize`
without relying on `std::path::Path` parsing.

The new implementation:

- Recognizes drive-letter, rooted, relative, and UNC paths.
- Treats both `\` and `/` as Windows path separators.
- Resolves `.` and `..` components lexically.
- Uses `\` as the normalized Windows path separator.
- Produces the same result regardless of the host platform.

## Testing

New test is added and tested with `cargo test -p util`, this test would
fail on current main branch.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- N/A or Added/Fixed/Improved ...
```

## Parents

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

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