Skip to content

Commit 8235ffd

Browse files
devsnekaddaleax
authored andcommitted
console: skip/strip %c formatting
Fixes: #29605 Refs: https://console.spec.whatwg.org PR-URL: #29606 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 8f06773 commit 8235ffd

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/api/util.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ property take precedence over `--trace-deprecation` and
185185
<!-- YAML
186186
added: v0.5.3
187187
changes:
188+
- version: REPLACEME
189+
pr-url: https://github.com/nodejs/node/pull/29606
190+
description: The `%c` specifier is ignored now.
188191
- version: v11.4.0
189192
pr-url: https://github.com/nodejs/node/pull/23708
190193
description: The `%d`, `%f` and `%i` specifiers now support Symbols
@@ -240,6 +243,8 @@ corresponding argument. Supported specifiers are:
240243
* `%O` - `Object`. A string representation of an object with generic JavaScript
241244
object formatting. Similar to `util.inspect()` without options. This will show
242245
the full object not including non-enumerable properties and proxies.
246+
* `%c` - `CSS`. This specifier is currently ignored, and will skip any CSS
247+
passed in.
243248
* `%%` - single percent sign (`'%'`). This does not consume an argument.
244249
* Returns: {string} The formatted string
245250

lib/internal/util/inspect.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,15 +1621,13 @@ function formatWithOptions(inspectOptions, ...args) {
16211621
tempStr = inspect(args[++a], inspectOptions);
16221622
break;
16231623
case 111: // 'o'
1624-
{
16251624
tempStr = inspect(args[++a], {
16261625
...inspectOptions,
16271626
showHidden: true,
16281627
showProxy: true,
16291628
depth: 4
16301629
});
16311630
break;
1632-
}
16331631
case 105: // 'i'
16341632
const tempInteger = args[++a];
16351633
if (typeof tempInteger === 'bigint') {
@@ -1648,6 +1646,10 @@ function formatWithOptions(inspectOptions, ...args) {
16481646
tempStr = formatNumber(stylizeNoColor, parseFloat(tempFloat));
16491647
}
16501648
break;
1649+
case 99: // 'c'
1650+
a += 1;
1651+
tempStr = '';
1652+
break;
16511653
case 37: // '%'
16521654
str += first.slice(lastPos, i);
16531655
lastPos = i + 1;

test/parallel/test-util-format.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ assert.strictEqual(util.format('abc%', 1), 'abc% 1');
317317
assert.strictEqual(util.format('%i', 1, 'number'), '1 number');
318318
assert.strictEqual(util.format('%i', 1, () => {}), '1 [Function (anonymous)]');
319319

320+
// %c from https://console.spec.whatwg.org/
321+
assert.strictEqual(util.format('%c'), '%c');
322+
assert.strictEqual(util.format('%cab'), '%cab');
323+
assert.strictEqual(util.format('%cab', 'color: blue'), 'ab');
324+
assert.strictEqual(util.format('%cab', 'color: blue', 'c'), 'ab c');
325+
320326
{
321327
const o = {};
322328
o.o = o;

0 commit comments

Comments
 (0)