1
1
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:
Wez Furlong 2022-07-25 07:21:07 -07:00
parent c32db29474
commit 23f36b2afb
2 changed files with 16 additions and 12 deletions

View File

@ -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()),

View File

@ -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()),