1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

Fix spawning new tabs/windows in directory with urlunsafe paths

The CWD is internally stored as URL. The path component is therefore
stored percent_encoded. It must be decoded before use.
This commit is contained in:
Arvedui 2021-05-15 22:05:10 +02:00 committed by Wez Furlong
parent bf0320624d
commit dbc278e59a
5 changed files with 25 additions and 10 deletions

2
Cargo.lock generated
View File

@ -4885,6 +4885,7 @@ dependencies = [
"open", "open",
"ordered-float", "ordered-float",
"palette", "palette",
"percent-encoding",
"portable-pty", "portable-pty",
"pretty_env_logger", "pretty_env_logger",
"promise", "promise",
@ -4972,6 +4973,7 @@ dependencies = [
"lazy_static", "lazy_static",
"log", "log",
"mux", "mux",
"percent-encoding",
"portable-pty", "portable-pty",
"promise", "promise",
"rangeset", "rangeset",

View File

@ -40,6 +40,7 @@ mux = { path = "../mux" }
open = "1.4" open = "1.4"
ordered-float = "2.1" ordered-float = "2.1"
palette = "0.5" palette = "0.5"
percent-encoding = "2"
portable-pty = { path = "../pty", features = ["serde_support", "ssh"]} portable-pty = { path = "../pty", features = ["serde_support", "ssh"]}
promise = { path = "../promise" } promise = { path = "../promise" }
pulldown-cmark = "0.8" pulldown-cmark = "0.8"

View File

@ -5,6 +5,7 @@ use mux::activity::Activity;
use mux::domain::DomainState; use mux::domain::DomainState;
use mux::tab::SplitDirection; use mux::tab::SplitDirection;
use mux::Mux; use mux::Mux;
use percent_encoding::percent_decode_str;
use portable_pty::{CommandBuilder, PtySize}; use portable_pty::{CommandBuilder, PtySize};
use std::sync::Arc; use std::sync::Arc;
@ -127,15 +128,19 @@ impl super::TermWindow {
} else { } else {
match cwd { match cwd {
Some(url) if url.scheme() == "file" => { Some(url) if url.scheme() == "file" => {
let path = url.path().to_string(); if let Ok(path) = percent_decode_str(url.path()).decode_utf8() {
// On Windows the file URI can produce a path like: let path = path.into_owned();
// `/C:\Users` which is valid in a file URI, but the leading slash // On Windows the file URI can produce a path like:
// is not liked by the windows file APIs, so we strip it off here. // `/C:\Users` which is valid in a file URI, but the leading slash
let bytes = path.as_bytes(); // is not liked by the windows file APIs, so we strip it off here.
if bytes.len() > 2 && bytes[0] == b'/' && bytes[2] == b':' { let bytes = path.as_bytes();
Some(path[1..].to_owned()) if bytes.len() > 2 && bytes[0] == b'/' && bytes[2] == b':' {
Some(path[1..].to_owned())
} else {
Some(path)
}
} else { } else {
Some(path) None
} }
} }
Some(_) | None => None, Some(_) | None => None,

View File

@ -16,6 +16,7 @@ hostname = "0.3"
lazy_static = "1.4" lazy_static = "1.4"
log = "0.4" log = "0.4"
mux = { path = "../mux" } mux = { path = "../mux" }
percent-encoding = "2"
portable-pty = { path = "../pty", features = ["serde_support"]} portable-pty = { path = "../pty", features = ["serde_support"]}
promise = { path = "../promise" } promise = { path = "../promise" }
rangeset = { path = "../rangeset" } rangeset = { path = "../rangeset" }

View File

@ -6,6 +6,7 @@ use mux::pane::{Pane, PaneId};
use mux::renderable::{RenderableDimensions, StableCursorPosition}; use mux::renderable::{RenderableDimensions, StableCursorPosition};
use mux::tab::TabId; use mux::tab::TabId;
use mux::Mux; use mux::Mux;
use percent_encoding::percent_decode_str;
use portable_pty::PtySize; use portable_pty::PtySize;
use promise::spawn::spawn_into_main_thread; use promise::spawn::spawn_into_main_thread;
use rangeset::RangeSet; use rangeset::RangeSet;
@ -611,8 +612,13 @@ async fn split_pane(split: SplitPane, sender: PduSender) -> anyhow::Result<Pdu>
let cwd = split.command_dir.or_else(|| { let cwd = split.command_dir.or_else(|| {
mux.get_pane(pane_id) mux.get_pane(pane_id)
.and_then(|pane| pane.get_current_working_dir()) .and_then(|pane| pane.get_current_working_dir())
.map(|url| { .and_then(|url| {
let path = url.path().to_string(); percent_decode_str(url.path())
.decode_utf8()
.ok()
.map(|path| path.into_owned())
})
.map(|path| {
// On Windows the file URI can produce a path like: // On Windows the file URI can produce a path like:
// `/C:\Users` which is valid in a file URI, but the leading slash // `/C:\Users` which is valid in a file URI, but the leading slash
// is not liked by the windows file APIs, so we strip it off here. // is not liked by the windows file APIs, so we strip it off here.