fix(windows): convert WSL paths to host-native format in /open-file command#9307
fix(windows): convert WSL paths to host-native format in /open-file command#9307OthmanAdi wants to merge 2 commits into
Conversation
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @OthmanAdi on file. In order for us to review and merge your code, each contributor must visit https://cla.warp.dev to read and agree to our CLA. Once you have done so, please comment |
|
I'm starting a first review of this pull request. You can follow along in the session on Warp. I requested changes on this pull request and posted feedback. Comment Powered by Oz |
|
@cla-bot check |
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @OthmanAdi on file. In order for us to review and merge your code, each contributor must visit https://cla.warp.dev to read and agree to our CLA. Once you have done so, please comment |
|
The cla-bot has been summoned, and re-checked this pull request! |
There was a problem hiding this comment.
Overview
This PR updates /open-file path resolution to run arguments through ShellLaunchData conversion before checking metadata, targeting WSL/MSYS2-style path encodings.
Concerns
- The new absolute-path heuristic overmatches relative filenames that contain colons, which can regress native executable sessions because
maybe_convert_absolute_pathreturns the relative path without joining it to the terminal CWD.
Verdict
Found: 0 critical, 1 important, 0 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
| let is_absolute = expanded_path_str.starts_with('/') | ||
| || expanded_path_str.starts_with('\\') | ||
| || expanded_path_str | ||
| .chars() | ||
| .next() | ||
| .is_some_and(|c: char| c.is_alphabetic()) | ||
| && expanded_path_str.contains(':'); |
There was a problem hiding this comment.
: (for example foo:bar) as absolute, so native sessions with launch data stop resolving those files relative to the terminal CWD.
| let is_absolute = expanded_path_str.starts_with('/') | |
| || expanded_path_str.starts_with('\\') | |
| || expanded_path_str | |
| .chars() | |
| .next() | |
| .is_some_and(|c: char| c.is_alphabetic()) | |
| && expanded_path_str.contains(':'); | |
| let has_windows_drive_prefix = expanded_path_str | |
| .as_bytes() | |
| .get(..3) | |
| .is_some_and(|bytes| { | |
| bytes[0].is_ascii_alphabetic() | |
| && bytes[1] == b':' | |
| && matches!(bytes[2], b'/' | b'\\') | |
| }); | |
| let is_absolute = expanded_path_str.starts_with('/') | |
| || expanded_path_str.starts_with('\\') | |
| || has_windows_drive_prefix; |
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @OthmanAdi on file. In order for us to review and merge your code, each contributor must visit https://cla.warp.dev to read and agree to our CLA. Once you have done so, please comment |
|
Updated the drive-letter detection to use a precise 3-byte check (letter + colon + slash) instead of the overly broad colon-in-string heuristic, as suggested. This avoids misidentifying relative paths like foo:bar as absolute. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
…ommand The /open-file slash command naively joined the user-provided path argument with the current working directory using PathBuf::join. In WSL sessions, both the CWD (reported via OSC 7) and the path argument are in Unix format (e.g. /home/user/file.txt), but PathBuf::join on Windows mangles the separators, producing broken paths. Use ShellLaunchData::maybe_convert_absolute_path and maybe_convert_relative_path to convert WSL/MSYS2 paths to their Windows-native equivalents before validating the file path. This reuses the same conversion already used for link detection and drag-and-drop. Closes warpdotdev#9191
Oz review requested this change. The previous heuristic matched any path containing a colon (e.g. foo:bar) as an absolute Windows path. Replace it with a precise 3-byte check that requires the pattern <letter>:<slash>, matching only genuine Windows drive-letter paths like C:/ or D:\\.
2f168c8 to
5ddd939
Compare
|
Hi @OthmanAdi — final reminder: a reviewer requested changes on this PR and it has been inactive for 37 days. It will be automatically closed in about 1 day(s) unless you push updates or reply. Maintainers can apply the |
|
Closing this pull request because the requested changes have gone unaddressed for over 30 days. If you'd like to continue, push your updates and reopen the PR (or comment to ask a maintainer to reopen) — we'd be glad to pick it back up. |
Description
Fixes #9191
The
/open-filecommand fails on Windows when the active session runs inside WSL. Paths like/home/user/project/file.txtget mangled during the join with the current working directory becausePathBuf::joinon Windows converts forward slashes to backslashes, producing broken paths.Root cause: In
app/src/terminal/input/slash_commands/mod.rs(line 496), the path argument is joined with the CWD usingcurrent_dir.join(&*expanded_path). For WSL sessions, both the CWD (reported via OSC 7 escape sequences) and the user's path argument are in Unix format.PathBuf::joinon Windows converts all/to\, producing mangled results like\home\user\project\file.txtinstead of the correct\\WSL$\Ubuntu\home\user\project\file.txt.The path conversion infrastructure already exists in
ShellLaunchData(maybe_convert_absolute_path,maybe_convert_relative_path) and is used for link detection and drag-and-drop, but was not applied to the/open-filecommand.Fix: Before joining paths, check if the session has a
ShellLaunchData(WSL, MSYS2, Docker). If so, usemaybe_convert_absolute_pathfor absolute paths andmaybe_convert_relative_pathfor relative paths to convert them to host-native format. Fall back to the naive join for native sessions (PowerShell, cmd).What this changes
/home/user/filemangled to\home\user\file\\WSL$\Ubuntu\home\user\file/mnt/c/)C:\Users\...launch_dataconversion)Testing
cargo check -p warppasses clean/open-file /home/user/.bashrcwith a valid absolute pathFile not foundwith mangled path\\WSL$\...pathlaunch_datameans the naive join path runs)Server API dependencies
Agent Mode
Changelog Entries for Stable
CHANGELOG-BUG-FIX: Fixed /open-file path resolution in WSL sessions on Windows, where forward slashes were incorrectly converted to backslashes.