mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: support tables with invalid UTF-8 keys in sendable data (#2890)
This commit is contained in:
parent
ec90f26ac3
commit
002b742cd9
2 changed files with 13 additions and 4 deletions
|
|
@ -190,11 +190,17 @@ impl Sendable {
|
||||||
fn value_to_key(value: Value) -> mlua::Result<DataKey> {
|
fn value_to_key(value: Value) -> mlua::Result<DataKey> {
|
||||||
Ok(match value {
|
Ok(match value {
|
||||||
Value::Nil => DataKey::Nil,
|
Value::Nil => DataKey::Nil,
|
||||||
Value::Boolean(v) => DataKey::Boolean(v),
|
Value::Boolean(b) => DataKey::Boolean(b),
|
||||||
Value::LightUserData(_) => Err("light userdata is not supported".into_lua_err())?,
|
Value::LightUserData(_) => Err("light userdata is not supported".into_lua_err())?,
|
||||||
Value::Integer(v) => DataKey::Integer(v),
|
Value::Integer(i) => DataKey::Integer(i),
|
||||||
Value::Number(v) => DataKey::Number(OrderedFloat::new(v)),
|
Value::Number(n) => DataKey::Number(OrderedFloat::new(n)),
|
||||||
Value::String(v) => DataKey::String(Cow::Owned(v.to_str()?.to_owned())),
|
Value::String(s) => {
|
||||||
|
if let Ok(s) = s.to_str() {
|
||||||
|
DataKey::String(s.to_owned().into())
|
||||||
|
} else {
|
||||||
|
DataKey::Bytes(s.as_bytes().to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
Value::Table(_) => Err("table is not supported".into_lua_err())?,
|
Value::Table(_) => Err("table is not supported".into_lua_err())?,
|
||||||
Value::Function(_) => Err("function is not supported".into_lua_err())?,
|
Value::Function(_) => Err("function is not supported".into_lua_err())?,
|
||||||
Value::Thread(_) => Err("thread is not supported".into_lua_err())?,
|
Value::Thread(_) => Err("thread is not supported".into_lua_err())?,
|
||||||
|
|
@ -234,6 +240,7 @@ impl Sendable {
|
||||||
DataKey::Id(i) => yazi_binding::Id(*i).into_lua(lua)?,
|
DataKey::Id(i) => yazi_binding::Id(*i).into_lua(lua)?,
|
||||||
DataKey::Url(u) => yazi_binding::Url::new(u.clone()).into_lua(lua)?,
|
DataKey::Url(u) => yazi_binding::Url::new(u.clone()).into_lua(lua)?,
|
||||||
DataKey::Urn(u) => yazi_binding::Urn::new(u.clone()).into_lua(lua)?,
|
DataKey::Urn(u) => yazi_binding::Urn::new(u.clone()).into_lua(lua)?,
|
||||||
|
DataKey::Bytes(b) => Value::String(lua.create_string(b)?),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,8 @@ pub enum DataKey {
|
||||||
Url(Url),
|
Url(Url),
|
||||||
#[serde(skip_deserializing)]
|
#[serde(skip_deserializing)]
|
||||||
Urn(UrnBuf),
|
Urn(UrnBuf),
|
||||||
|
#[serde(skip)]
|
||||||
|
Bytes(Vec<u8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DataKey {
|
impl DataKey {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue