Fix Stack Overflow while Formatting Tables with Circular Keys (#183)

This commit is contained in:
Erica Marigold 2024-04-18 15:59:23 +05:30 committed by GitHub
parent 34fc23d024
commit fe55442dac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -130,7 +130,7 @@ pub fn pretty_format_value(
} else if let Some(s) = call_table_tostring_metamethod(tab) { } else if let Some(s) = call_table_tostring_metamethod(tab) {
write!(buffer, "{s}")?; write!(buffer, "{s}")?;
} else if depth >= 1 && parent_table_addr.eq(&table_addr) { } else if depth >= 1 && parent_table_addr.eq(&table_addr) {
write!(buffer, "{}", STYLE_DIM.apply_to("<self>"))? write!(buffer, "{}", STYLE_DIM.apply_to("<self>"))?;
} else { } else {
let mut is_empty = false; let mut is_empty = false;
let depth_indent = INDENT.repeat(depth); let depth_indent = INDENT.repeat(depth);
@ -148,7 +148,12 @@ pub fn pretty_format_value(
)?, )?,
_ => { _ => {
write!(buffer, "\n{depth_indent}{INDENT}[")?; 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("="))?; write!(buffer, "] {} ", STYLE_DIM.apply_to("="))?;
} }
} }