Skip to content

fix(windows): convert WSL paths to host-native format in /open-file command#9307

Closed
OthmanAdi wants to merge 2 commits into
warpdotdev:masterfrom
OthmanAdi:othmanadi/fix-wsl-path-open-file
Closed

fix(windows): convert WSL paths to host-native format in /open-file command#9307
OthmanAdi wants to merge 2 commits into
warpdotdev:masterfrom
OthmanAdi:othmanadi/fix-wsl-path-open-file

Conversation

@OthmanAdi
Copy link
Copy Markdown

Description

Fixes #9191

The /open-file command fails on Windows when the active session runs inside WSL. Paths like /home/user/project/file.txt get mangled during the join with the current working directory because PathBuf::join on 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 using current_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::join on Windows converts all / to \, producing mangled results like \home\user\project\file.txt instead 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-file command.

Fix: Before joining paths, check if the session has a ShellLaunchData (WSL, MSYS2, Docker). If so, use maybe_convert_absolute_path for absolute paths and maybe_convert_relative_path for relative paths to convert them to host-native format. Fall back to the naive join for native sessions (PowerShell, cmd).

What this changes

Session type Before After
WSL (absolute path) /home/user/file mangled to \home\user\file Converts to \\WSL$\Ubuntu\home\user\file
WSL (relative path) Joins Unix CWD with Unix relative path on Windows Converts CWD + relative to host-native
WSL (/mnt/c/) Path separators mangled Converts to C:\Users\...
PowerShell No change (naive join works) No change (no launch_data conversion)

Testing

  • cargo check -p warp passes clean
  • Manual testing on Windows 11 with WSL:
    1. Open a WSL session in Warp
    2. Run /open-file /home/user/.bashrc with a valid absolute path
    3. Before fix: File not found with mangled path
    4. After fix: file opens in Warp editor with correct \\WSL$\... path
  • Native PowerShell sessions remain unaffected (no launch_data means the naive join path runs)

Server API dependencies

  • N/A

Agent Mode

  • Warp 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.

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 28, 2026

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 @cla-bot check to trigger another check.

@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented Apr 28, 2026

@OthmanAdi

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 /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@OthmanAdi
Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 28, 2026

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 @cla-bot check to trigger another check.

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 28, 2026

The cla-bot has been summoned, and re-checked this pull request!

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_path returns 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

Comment on lines +494 to +500
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(':');
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.

⚠️ [IMPORTANT] Drive-letter detection treats any relative path that starts with a letter and contains : (for example foo:bar) as absolute, so native sessions with launch data stop resolving those files relative to the terminal CWD.

Suggested change
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;

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 28, 2026

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 @cla-bot check to trigger another check.

@OthmanAdi
Copy link
Copy Markdown
Author

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.

@OthmanAdi
Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Apr 29, 2026
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 29, 2026

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:\\.
@OthmanAdi OthmanAdi force-pushed the othmanadi/fix-wsl-path-open-file branch from 2f168c8 to 5ddd939 Compare April 29, 2026 06:01
@captainsafia captainsafia added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Apr 30, 2026 — with Warp Dev Github Integration
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

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 no-autoclose label to keep it open.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

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.

@github-actions github-actions Bot closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] /open-file mangles WSL paths - final path separator converted from / to \

2 participants