Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5ed8a1c

Browse filesBrowse files
BridgeARtargos
authored andcommitted
util: do not reduce to a single line if not appropriate using inspect
This makes sure entries are not lined up on a single line if the content contains any new line. That would otherwise cause confusing output. Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> PR-URL: #41083 Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e3a0a9c commit 5ed8a1c
Copy full SHA for 5ed8a1c

File tree

Expand file treeCollapse file tree

2 files changed

+23
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,8 +1931,11 @@ function reduceToSingleString(
19311931
const start = output.length + ctx.indentationLvl +
19321932
braces[0].length + base.length + 10;
19331933
if (isBelowBreakLength(ctx, output, start, base)) {
1934-
return `${base ? `${base} ` : ''}${braces[0]} ${join(output, ', ')}` +
1935-
` ${braces[1]}`;
1934+
const joinedOutput = join(output, ', ');
1935+
if (!joinedOutput.includes('\n')) {
1936+
return `${base ? `${base} ` : ''}${braces[0]} ${joinedOutput}` +
1937+
` ${braces[1]}`;
1938+
}
19361939
}
19371940
}
19381941
}
Collapse file

‎test/parallel/test-util-inspect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,6 +2631,24 @@ assert.strictEqual(
26312631

26322632
assert.strictEqual(out, expected);
26332633

2634+
// Array grouping should prevent lining up outer elements on a single line.
2635+
obj = [[[1, 2, 3, 4, 5, 6, 7, 8, 9]]];
2636+
2637+
out = util.inspect(obj, { compact: 3 });
2638+
2639+
expected = [
2640+
'[',
2641+
' [',
2642+
' [',
2643+
' 1, 2, 3, 4, 5,',
2644+
' 6, 7, 8, 9',
2645+
' ]',
2646+
' ]',
2647+
']',
2648+
].join('\n');
2649+
2650+
assert.strictEqual(out, expected);
2651+
26342652
// Verify that array grouping and line consolidation does not happen together.
26352653
obj = {
26362654
a: {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.