From 88ff7158f00ee877ec87599e547315c87e448064 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Wed, 17 Apr 2024 12:09:32 +0530 Subject: [PATCH] fix(formatting): fix recursion with circular keys Fixes a stack overflow caused when printing a table with circular keys by incrementing the depth argument when recursing and formatting table keys. --- src/lune/util/formatting.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lune/util/formatting.rs b/src/lune/util/formatting.rs index 19f9a88..9d5eba0 100644 --- a/src/lune/util/formatting.rs +++ b/src/lune/util/formatting.rs @@ -130,7 +130,7 @@ pub fn pretty_format_value( } else if let Some(s) = call_table_tostring_metamethod(tab) { write!(buffer, "{s}")?; } else if depth >= 1 && parent_table_addr.eq(&table_addr) { - write!(buffer, "{}", STYLE_DIM.apply_to(""))? + write!(buffer, "{}", STYLE_DIM.apply_to(""))?; } else { let mut is_empty = false; let depth_indent = INDENT.repeat(depth); @@ -148,7 +148,7 @@ pub fn pretty_format_value( )?, _ => { write!(buffer, "\n{depth_indent}{INDENT}[")?; - pretty_format_value(buffer, &key, parent_table_addr.clone(), depth)?; + pretty_format_value(buffer, &key, parent_table_addr.clone(), depth + 1)?; write!(buffer, "] {} ", STYLE_DIM.apply_to("="))?; } }