Skip to content

Commit

Permalink
console: skip/strip %c formatting
Browse files Browse the repository at this point in the history
Fixes: #29605
Refs: https://console.spec.whatwg.org
PR-URL: #29606
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
devsnek authored and BridgeAR committed Sep 25, 2019
1 parent 6ba39d4 commit f61c509
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ property take precedence over `--trace-deprecation` and
<!-- YAML
added: v0.5.3
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/29606
description: The `%c` specifier is ignored now.
- version: v11.4.0
pr-url: https://github.com/nodejs/node/pull/23708
description: The `%d`, `%f` and `%i` specifiers now support Symbols
Expand Down Expand Up @@ -240,6 +243,8 @@ corresponding argument. Supported specifiers are:
* `%O` - `Object`. A string representation of an object with generic JavaScript
object formatting. Similar to `util.inspect()` without options. This will show
the full object not including non-enumerable properties and proxies.
* `%c` - `CSS`. This specifier is currently ignored, and will skip any CSS
passed in.
* `%%` - single percent sign (`'%'`). This does not consume an argument.
* Returns: {string} The formatted string

Expand Down
6 changes: 4 additions & 2 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1596,15 +1596,13 @@ function formatWithOptions(inspectOptions, ...args) {
tempStr = inspect(args[++a], inspectOptions);
break;
case 111: // 'o'
{
tempStr = inspect(args[++a], {
...inspectOptions,
showHidden: true,
showProxy: true,
depth: 4
});
break;
}
case 105: // 'i'
const tempInteger = args[++a];
if (typeof tempInteger === 'bigint') {
Expand All @@ -1623,6 +1621,10 @@ function formatWithOptions(inspectOptions, ...args) {
tempStr = formatNumber(stylizeNoColor, parseFloat(tempFloat));
}
break;
case 99: // 'c'
a += 1;
tempStr = '';
break;
case 37: // '%'
str += first.slice(lastPos, i);
lastPos = i + 1;
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-util-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ assert.strictEqual(util.format('abc%', 1), 'abc% 1');
assert.strictEqual(util.format('%i', 1, 'number'), '1 number');
assert.strictEqual(util.format('%i', 1, () => {}), '1 [Function]');

// %c from https://console.spec.whatwg.org/
assert.strictEqual(util.format('%c'), '%c');
assert.strictEqual(util.format('%cab'), '%cab');
assert.strictEqual(util.format('%cab', 'color: blue'), 'ab');
assert.strictEqual(util.format('%cab', 'color: blue', 'c'), 'ab c');

{
const o = {};
o.o = o;
Expand Down

0 comments on commit f61c509

Please sign in to comment.