Skip to content

A table cell containing a newline splits its row, silently #748

Closed

Description

@David-Noble-at-work

A cell containing a newline splits its row, and the split is silent.

Reproduction

Every shell result carries a stdout field, and stdout ends in a newline. So this is the ordinary case,
not an edge one:

$ devlore-test run -o table --jq '.results' test_hello.star
COMMAND              EXIT  STDERR  STDOUT
echo "Hello World!"  0             Hello World!
                                                <- the row ended here, mid-record

Byte-level, the row is echo "Hello World!" 0 Hello World!\n followed by a second \n: the
cell's own newline terminated the line, and tabwriter then wrote the row's terminator onto the next one.
A reader sees one record rendered as two lines, with the second one blank.

Why csv is unaffected

csv quotes, so the newline lands inside the quoted field and a parser still reads one record:

command,exit,stderr,stdout
"echo ""Hello World!""",0,,"Hello World!
"

That is the quoting rationale that retired tsv, working exactly as argued.

value splits too, and that is correct: raw is raw, gcloud and aws behave the same, and the caller is
expected to project with --jq first. table has no such contract. It renders for a person, and a person
reading a split row is being misinformed about how many records there are.

The fix

Escape control characters in a table cell -- a newline as the two characters \n, a tab as \t, a
carriage return as \r. kubectl and aws both do this rather than wrap, and it keeps one record on one
line, which is the property that makes an aligned table readable at all.

Scope is pkg/result/table.go alone. csv must NOT change: RFC 4180 quoting already handles the case
correctly, and escaping there would corrupt a field that a parser round-trips today. value must not change
either, for the reason above.

Verification

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions