Skip to content

fix(cpp): escape control characters in tsfile-cli table output - #974

Merged
ColinLeeo merged 2 commits into
apache:developfrom
ColinLeeo:colin/fix-table-output-escape
Oct 8, 2026
Merged

ColinLeeo merged 2 commits into
apache:developfrom
ColinLeeo:colin/fix-table-output-escape

Conversation

@ColinLeeo

Copy link
Copy Markdown
Contributor

The readable 'table' format emitted string cells verbatim, so an embedded newline split one logical record across multiple physical lines and other control characters rendered invisibly. Downstream line-based consumers then misparsed the output with no error.

Render backslash, newline, carriage return and tab as the two-character literals \, \n, \r and \t, and every other non-printable control byte (C0 controls plus DEL) as \uXXXX. CSV and NDJSON output are unchanged.

Add unit coverage for the new table_escape() helper (named controls, unicode escapes, DEL boundary, UTF-8 passthrough, column alignment) and a CLI end-to-end test asserting exact table/csv/ndjson output for cells that embed control characters.

The readable 'table' format emitted string cells verbatim, so an embedded newline split one logical record across multiple physical lines and other control characters rendered invisibly. Downstream line-based consumers then misparsed the output with no error.

Render backslash, newline, carriage return and tab as the two-character literals \\, \n, \r and \t, and every other non-printable control byte (C0 controls plus DEL) as \uXXXX. CSV and NDJSON output are unchanged.

Add unit coverage for the new table_escape() helper (named controls, unicode escapes, DEL boundary, UTF-8 passthrough, column alignment) and a CLI end-to-end test asserting exact table/csv/ndjson output for cells that embed control characters.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation is focused, consistent with the stated behavior, and covered by unit and end-to-end tests.

0 open findings

What changed in this PR

Escapes control bytes in human-readable C++ CLI table output while preserving CSV and NDJSON behavior.

Changes:

  • Adds table_escape() and applies it to table cells and headers.
  • Updates column-width calculations for escaped content.
  • Adds unit and end-to-end coverage for controls, UTF-8, and alignment.
File Description
cpp/​tools/​format/​output_format.h Declares table_escape().
cpp/​tools/​format/​output_format.cc Implements and applies table escaping.
cpp/​test/​tools/​output_format_test.cc Tests escaping and alignment.
cpp/​test/​tools/​model_format_e2e_test.cc Verifies exact CLI output formats.
cpp/​test/​tools/​cli_test_util.h Adds a control-character fixture.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@ColinLeeo
ColinLeeo merged commit fce6c42 into apache:develop Oct 8, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants