Skip to content

Commit d77f623

Browse files
bartlomiejuclaude
andauthored
fix(console): prevent multi-line object values in console.table (#32604)
## Summary - Objects in `console.table` could break the table layout when their `Deno.inspect` output exceeded the default `breakLength` (72 chars), causing some rows to wrap across multiple lines - Fix: set `breakLength: Infinity` in the inspect options for table cell values, ensuring single-line rendering Before: ``` │ 1 │ "371fe41e-..." │ { id: "371fe41e-...", name: "Deutsche Bahn", countryCode: "DE" } │ ``` After: ``` │ 1 │ "371fe41e-..." │ { id: "371fe41e-...", name: "Deutsche Bahn", countryCode: "DE" } │ ``` Fixes #18828 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d7e449d commit d77f623

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

ext/web/01_console.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,6 +3771,7 @@ class Console {
37713771
...getConsoleInspectOptions(noColorStdout()),
37723772
depth: 1,
37733773
compact: true,
3774+
breakLength: Infinity,
37743775
});
37753776
const toTable = (header, body) => this.log(cliTable(header, body));
37763777

tests/unit/console_test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,35 @@ Deno.test(function consoleTable() {
17221722
`,
17231723
);
17241724
});
1725+
// Objects with long values should stay on a single line (#18828)
1726+
mockConsole((console, out) => {
1727+
console.table([
1728+
["b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068", {
1729+
id: "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068",
1730+
name: "Trenitalia",
1731+
countryCode: "IT",
1732+
}],
1733+
["371fe41e-349c-40b7-be93-10c58fbbb95f", {
1734+
id: "371fe41e-349c-40b7-be93-10c58fbbb95f",
1735+
name: "Deutsche Bahn",
1736+
countryCode: "DE",
1737+
}],
1738+
]);
1739+
const output = stripAnsiCode(out.toString());
1740+
// Each row should be a single line (no newlines within cell values)
1741+
const rows = output.split("\n").filter((line) => line.startsWith("│"));
1742+
for (const row of rows) {
1743+
// The row should not contain embedded newlines (the cell value should be flat)
1744+
assert(!row.includes("\n "), "Table row should be single-line");
1745+
}
1746+
// Verify object values are rendered on one line
1747+
assert(
1748+
output.includes(
1749+
'name: "Deutsche Bahn", countryCode: "DE"',
1750+
),
1751+
"Object should be on single line",
1752+
);
1753+
});
17251754
mockConsole((console, out) => {
17261755
console.table([]);
17271756
assertEquals(

0 commit comments

Comments
 (0)