mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: encode the uri list
This commit is contained in:
parent
b4c491afac
commit
54a760d8f4
8 changed files with 34 additions and 15 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -6140,6 +6140,7 @@ dependencies = [
|
|||
"base64",
|
||||
"hashbrown 0.17.1",
|
||||
"mlua",
|
||||
"percent-encoding",
|
||||
"ratatui",
|
||||
"serde",
|
||||
"thiserror 2.0.18",
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ impl Tty {
|
|||
})
|
||||
}
|
||||
b"FinishDrop" => match &*t.raw_get::<BorrowedBytes>("type")? {
|
||||
b"copy" => write!(w, "{}", FinishDrop::Move),
|
||||
b"copy" => write!(w, "{}", FinishDrop::Copy),
|
||||
b"move" => write!(w, "{}", FinishDrop::Move),
|
||||
_ => return Err("invalid FinishDrop type".into_lua_err()),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ local M = {}
|
|||
function M.selected_uri_list()
|
||||
local paths = {}
|
||||
for _, u in pairs(cx.active.selected) do
|
||||
paths[#paths + 1] = string.format("file://%s", u.path)
|
||||
paths[#paths + 1] = "file://" .. ya.percent_encode(tostring(u.path))
|
||||
end
|
||||
if #paths == 0 and cx.active.current.hovered then
|
||||
paths[1] = string.format("file://%s", cx.active.current.hovered.path)
|
||||
paths[1] = "file://" .. ya.percent_encode(tostring(cx.active.current.hovered.path))
|
||||
end
|
||||
return paths
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use std::borrow::Cow;
|
|||
|
||||
use mlua::{Function, Lua};
|
||||
use twox_hash::XxHash3_128;
|
||||
use yazi_shim::RFC_3986;
|
||||
use yazi_widgets::CLIPBOARD;
|
||||
|
||||
use super::Utils;
|
||||
|
|
@ -45,4 +46,14 @@ impl Utils {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn percent_encode(lua: &Lua) -> mlua::Result<Function> {
|
||||
lua.create_function(|lua, s: mlua::String| {
|
||||
let b = s.as_bytes();
|
||||
match percent_encoding::percent_encode(&b, RFC_3986).into() {
|
||||
Cow::Borrowed(_) => Ok(s),
|
||||
Cow::Owned(s) => lua.create_external_string(s),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ pub fn compose(
|
|||
b"hash" => Utils::hash(lua)?,
|
||||
b"quote" => Utils::quote(lua)?,
|
||||
b"clipboard" => Utils::clipboard(lua)?,
|
||||
b"percent_encode" => Utils::percent_encode(lua)?,
|
||||
b"percent_decode" => Utils::percent_decode(lua)?,
|
||||
|
||||
// Time
|
||||
|
|
|
|||
|
|
@ -20,16 +20,17 @@ vendored-lua = [ "mlua/vendored" ]
|
|||
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
||||
|
||||
# External dependencies
|
||||
arc-swap = { workspace = true }
|
||||
base64 = { workspace = true }
|
||||
hashbrown = { workspace = true }
|
||||
mlua = { workspace = true }
|
||||
ratatui = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
twox-hash = { workspace = true }
|
||||
unicode-width = { workspace = true }
|
||||
arc-swap = { workspace = true }
|
||||
base64 = { workspace = true }
|
||||
hashbrown = { workspace = true }
|
||||
mlua = { workspace = true }
|
||||
percent-encoding = { workspace = true }
|
||||
ratatui = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
twox-hash = { workspace = true }
|
||||
unicode-width = { workspace = true }
|
||||
|
||||
[dependencies.unicode-segmentation]
|
||||
version = "1.13.2"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
yazi_macro::mod_pub!(arc_swap base64 cell mlua path ratatui serde strum toml vec);
|
||||
yazi_macro::mod_pub!(arc_swap cell mlua path ratatui serde strum toml vec);
|
||||
|
||||
yazi_macro::mod_flat!(twox utf8);
|
||||
yazi_macro::mod_flat!(base64 percent_encoding twox utf8);
|
||||
|
||||
#[cfg(windows)]
|
||||
yazi_macro::mod_flat!(win32);
|
||||
|
|
|
|||
5
yazi-shim/src/percent_encoding.rs
Normal file
5
yazi-shim/src/percent_encoding.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
use percent_encoding::{AsciiSet, NON_ALPHANUMERIC};
|
||||
|
||||
// RFC 3986 path component: encode everything that is not a safe path character.
|
||||
pub const RFC_3986: &AsciiSet =
|
||||
&NON_ALPHANUMERIC.remove(b'-').remove(b'.').remove(b'_').remove(b'~');
|
||||
Loading…
Add table
Reference in a new issue