mirror of
https://github.com/wez/wezterm.git
synced 2024-11-26 08:25:50 +03:00
json: fix visited hash set
We were skipping scalars/primitive values, which wasn't the intent. refs: https://github.com/wez/wezterm/issues/2302
This commit is contained in:
parent
c32db29474
commit
23f36b2afb
@ -52,13 +52,15 @@ fn json_parse<'lua>(lua: &'lua Lua, text: String) -> mlua::Result<LuaValue> {
|
||||
}
|
||||
|
||||
fn lua_value_to_json_value(value: LuaValue, visited: &mut HashSet<usize>) -> mlua::Result<JValue> {
|
||||
let ptr = value.to_pointer() as usize;
|
||||
if visited.contains(&ptr) {
|
||||
// Skip this one, as we've seen it before.
|
||||
// Treat it as a Null value.
|
||||
return Ok(JValue::Null);
|
||||
if let LuaValue::Table(_) = &value {
|
||||
let ptr = value.to_pointer() as usize;
|
||||
if visited.contains(&ptr) {
|
||||
// Skip this one, as we've seen it before.
|
||||
// Treat it as a Null value.
|
||||
return Ok(JValue::Null);
|
||||
}
|
||||
visited.insert(ptr);
|
||||
}
|
||||
visited.insert(ptr);
|
||||
Ok(match value {
|
||||
LuaValue::Nil => JValue::Null,
|
||||
LuaValue::String(s) => JValue::String(s.to_str()?.to_string()),
|
||||
|
@ -95,13 +95,15 @@ fn lua_value_to_dynamic_impl(
|
||||
value: LuaValue,
|
||||
visited: &mut HashSet<usize>,
|
||||
) -> mlua::Result<DynValue> {
|
||||
let ptr = value.to_pointer() as usize;
|
||||
if visited.contains(&ptr) {
|
||||
// Skip this one, as we've seen it before.
|
||||
// Treat it as a Null value.
|
||||
return Ok(DynValue::Null);
|
||||
if let LuaValue::Table(_) = &value {
|
||||
let ptr = value.to_pointer() as usize;
|
||||
if visited.contains(&ptr) {
|
||||
// Skip this one, as we've seen it before.
|
||||
// Treat it as a Null value.
|
||||
return Ok(DynValue::Null);
|
||||
}
|
||||
visited.insert(ptr);
|
||||
}
|
||||
visited.insert(ptr);
|
||||
Ok(match value {
|
||||
LuaValue::Nil => DynValue::Null,
|
||||
LuaValue::String(s) => DynValue::String(s.to_str()?.to_string()),
|
||||
|
Loading…
Reference in New Issue
Block a user