fix(tui): escape pipes in table fallback rows

This commit is contained in:
Felipe Coury
2026-04-06 13:14:40 -03:00
committed by Felipe Coury
parent be9006c161
commit 7b7f233e36
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -1240,7 +1240,7 @@ where
out.push('|');
for cell in row {
out.push(' ');
out.push_str(&cell.plain_text());
out.push_str(&cell.plain_text().replace('|', "\\|"));
out.push(' ');
out.push('|');
}
+14
View File
@@ -1461,6 +1461,20 @@ fn table_falls_back_to_pipe_rendering_if_it_cannot_fit() {
assert!(!lines.iter().any(|line| line.contains('┌')));
}
#[test]
fn table_pipe_fallback_escapes_literal_pipes_in_cell_content() {
let md = "| c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10 |\n|---|---|---|---|---|---|---|---|---|---|\n| keep | keep | keep | keep | keep | keep | keep | keep | a \\| b | keep |\n";
let text = crate::markdown_render::render_markdown_text_with_width(md, Some(20));
let lines: Vec<String> = text
.lines
.iter()
.map(|line| line.spans.iter().map(|span| span.content.clone()).collect())
.collect();
assert!(lines.first().is_some_and(|line| line.starts_with('|')));
assert!(lines.iter().any(|line| line.contains("a \\| b")));
}
#[test]
fn table_keeps_sparse_rows_with_empty_trailing_cells() {
let md = "| A | B | C |\n|---|---|---|\n| a | | |\n";