zed/crates/path
Xin Zhao 2610332077
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`:


914e1c9873/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 ...
2026-07-31 06:41:53 +00:00
..
src path: Normalize Windows paths independently of the host platform (#61374) 2026-07-31 06:41:53 +00:00
Cargo.toml Fix path's license (#61955) 2026-07-30 20:40:26 +00:00
LICENSE-APACHE