Skip to content

Commit f61c509

Browse files
devsnekBridgeAR
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 6ba39d4 commit f61c509

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/api/util.md

+5
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1596,15 +1596,13 @@ function formatWithOptions(inspectOptions, ...args) {
15961596
tempStr = inspect(args[++a], inspectOptions);
15971597
break;
15981598
case 111: // 'o'
1599-
{
16001599
tempStr = inspect(args[++a], {
16011600
...inspectOptions,
16021601
showHidden: true,
16031602
showProxy: true,
16041603
depth: 4
16051604
});
16061605
break;
1607-
}
16081606
case 105: // 'i'
16091607
const tempInteger = args[++a];
16101608
if (typeof tempInteger === 'bigint') {
@@ -1623,6 +1621,10 @@ function formatWithOptions(inspectOptions, ...args) {
16231621
tempStr = formatNumber(stylizeNoColor, parseFloat(tempFloat));
16241622
}
16251623
break;
1624+
case 99: // 'c'
1625+
a += 1;
1626+
tempStr = '';
1627+
break;
16261628
case 37: // '%'
16271629
str += first.slice(lastPos, i);
16281630
lastPos = i + 1;

test/parallel/test-util-format.js

+6
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]');
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)