Skip to content

Commit 2d55c94

Browse files
authored
fix: prevent quotes in file(1) arguments from being stripped under MSYS2 (#3364)
1 parent c725c91 commit 2d55c94

File tree

6 files changed

+54
-12
lines changed

6 files changed

+54
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
7373
- Force Git checkout for plugin cache repositories ([#3169])
7474
- Check compatibility when reusing previewer bytecode cache ([#3190])
7575
- Disable kitty keyboard protocol on Windows due to `crossterm` inability to handle it ([#3250])
76+
- Prevent quotes in file(1) arguments from being stripped under MSYS2 ([#3364])
7677
- Expose `ya` CLI in the Snap build ([#2904])
7778
- Fallback to `PollWatcher` for file changes watching on NetBSD ([#2941])
7879
- Generate unique image IDs for Kgp to tolerate tmux ([#3038])
@@ -1540,3 +1541,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
15401541
[#3313]: https://github.com/sxyazi/yazi/pull/3313
15411542
[#3317]: https://github.com/sxyazi/yazi/pull/3317
15421543
[#3360]: https://github.com/sxyazi/yazi/pull/3360
1544+
[#3364]: https://github.com/sxyazi/yazi/pull/3364

Cargo.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ hashbrown = { version = "0.16.1", features = [ "serde" ] }
3535
indexmap = { version = "2.12.1", features = [ "serde" ] }
3636
libc = "0.2.177"
3737
lru = "0.16.2"
38-
mlua = { version = "0.11.4", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serde" ] }
38+
mlua = { version = "0.11.5", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serde" ] }
3939
objc2 = "0.6.3"
4040
ordered-float = { version = "5.1.0", features = [ "serde" ] }
4141
parking_lot = "0.12.5"

yazi-plugin/preset/plugins/mime-local.lua

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ local function match_mimetype(line)
1515
end
1616
end
1717

18+
local function spawn_file1(paths)
19+
local bin = os.getenv("YAZI_FILE_ONE") or "file"
20+
local windows = ya.target_family() == "windows"
21+
22+
local cmd = Command(bin):arg({ "-bL", "--mime-type" }):stdout(Command.PIPED)
23+
if windows then
24+
cmd:arg({ "-f", "-" }):stdin(Command.PIPED)
25+
else
26+
cmd:arg("--"):arg(paths)
27+
end
28+
29+
local child, err = cmd:spawn()
30+
if not child then
31+
return nil, Err("Failed to start `%s`, error: %s", bin, err)
32+
elseif windows then
33+
child:write_all(table.concat(paths, "\n"))
34+
child:flush()
35+
ya.drop(child:take_stdin())
36+
end
37+
38+
return child
39+
end
40+
1841
function M:fetch(job)
1942
local urls, paths = {}, {}
2043
for i, file in ipairs(job.files) do
@@ -25,10 +48,9 @@ function M:fetch(job)
2548
end
2649
end
2750

28-
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
29-
local child, err = Command(cmd):arg({ "-bL", "--mime-type", "--" }):arg(paths):stdout(Command.PIPED):spawn()
51+
local child, err = spawn_file1(paths)
3052
if not child then
31-
return true, Err("Failed to start `%s`, error: %s", cmd, err)
53+
return true, err
3254
end
3355

3456
local updates, last = {}, ya.time()

yazi-plugin/src/utils/app.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use std::any::TypeId;
2+
13
use mlua::{AnyUserData, ExternalError, Function, Lua};
4+
use tokio::process::{ChildStderr, ChildStdin, ChildStdout};
25
use yazi_binding::{Id, Permit, PermitRef, deprecate};
36
use yazi_proxy::{AppProxy, HIDER};
47

@@ -15,6 +18,19 @@ impl Utils {
1518
})
1619
}
1720

21+
pub(super) fn drop(lua: &Lua) -> mlua::Result<Function> {
22+
lua.create_function(|_, ud: AnyUserData| {
23+
match ud.type_id() {
24+
Some(t) if t == TypeId::of::<ChildStdin>() => {}
25+
Some(t) if t == TypeId::of::<ChildStdout>() => {}
26+
Some(t) if t == TypeId::of::<ChildStderr>() => {}
27+
Some(t) => Err(format!("Cannot drop userdata of type {t:?}").into_lua_err())?,
28+
None => Err("Cannot drop scoped userdata".into_lua_err())?,
29+
};
30+
ud.destroy()
31+
})
32+
}
33+
1834
pub(super) fn hide(lua: &Lua) -> mlua::Result<Function> {
1935
lua.create_async_function(|lua, ()| async move {
2036
deprecate!(lua, "`ya.hide()` is deprecated, use `ui.hide()` instead, in your {}\nSee #2939 for more details: https://github.com/sxyazi/yazi/pull/2939");

yazi-plugin/src/utils/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub fn compose(
1010
match key {
1111
// App
1212
b"id" => Utils::id(lua)?,
13+
b"drop" => Utils::drop(lua)?,
1314
b"hide" => Utils::hide(lua)?,
1415

1516
// Cache

0 commit comments

Comments
 (0)