Decode URL from openURLs to handle percent encoded paths

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Julia 2023-01-24 18:48:15 -05:00
parent 52296836fe
commit 0414723a54
4 changed files with 9 additions and 4 deletions

1
Cargo.lock generated
View File

@ -8310,6 +8310,7 @@ dependencies = [
"tree-sitter-typescript", "tree-sitter-typescript",
"unindent", "unindent",
"url", "url",
"urlencoding",
"util", "util",
"vim", "vim",
"workspace", "workspace",

View File

@ -853,8 +853,8 @@ extern "C" fn open_urls(this: &mut Object, _: Sel, _: id, urls: id) {
(0..urls.count()) (0..urls.count())
.into_iter() .into_iter()
.filter_map(|i| { .filter_map(|i| {
let path = urls.objectAtIndex(i); let url = urls.objectAtIndex(i);
match CStr::from_ptr(path.absoluteString().UTF8String() as *mut c_char).to_str() { match CStr::from_ptr(url.absoluteString().UTF8String() as *mut c_char).to_str() {
Ok(string) => Some(string.to_string()), Ok(string) => Some(string.to_string()),
Err(err) => { Err(err) => {
log::error!("error converting path to string: {}", err); log::error!("error converting path to string: {}", err);

View File

@ -110,6 +110,7 @@ tree-sitter-html = "0.19.0"
tree-sitter-scheme = { git = "https://github.com/6cdh/tree-sitter-scheme", rev = "af0fd1fa452cb2562dc7b5c8a8c55551c39273b9"} tree-sitter-scheme = { git = "https://github.com/6cdh/tree-sitter-scheme", rev = "af0fd1fa452cb2562dc7b5c8a8c55551c39273b9"}
tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a"} tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a"}
url = "2.2" url = "2.2"
urlencoding = "2.1.2"
[dev-dependencies] [dev-dependencies]
call = { path = "../call", features = ["test-support"] } call = { path = "../call", features = ["test-support"] }

View File

@ -32,8 +32,8 @@ use settings::{
}; };
use simplelog::ConfigBuilder; use simplelog::ConfigBuilder;
use smol::process::Command; use smol::process::Command;
use std::fs::OpenOptions;
use std::{env, ffi::OsStr, panic, path::PathBuf, sync::Arc, thread, time::Duration}; use std::{env, ffi::OsStr, panic, path::PathBuf, sync::Arc, thread, time::Duration};
use std::{fs::OpenOptions, os::unix::prelude::OsStrExt};
use terminal_view::{get_working_directory, TerminalView}; use terminal_view::{get_working_directory, TerminalView};
use fs::RealFs; use fs::RealFs;
@ -90,7 +90,10 @@ fn main() {
let paths: Vec<_> = urls let paths: Vec<_> = urls
.iter() .iter()
.flat_map(|url| url.strip_prefix("file://")) .flat_map(|url| url.strip_prefix("file://"))
.map(|path| PathBuf::from(path)) .map(|url| {
let decoded = urlencoding::decode_binary(url.as_bytes());
PathBuf::from(OsStr::from_bytes(decoded.as_ref()))
})
.collect(); .collect();
open_paths_tx open_paths_tx
.unbounded_send(paths) .unbounded_send(paths)