console: skip/strip %c formatting

Fixes: https://github.com/nodejs/node/issues/29605
Refs: https://console.spec.whatwg.org
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Gus Caplan 2019-09-18 16:21:47 -05:00 committed by Anna Henningsen
parent 8f06773a8c
commit 8235ffd786
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
3 changed files with 15 additions and 2 deletions

View File

@ -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
@ -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

View File

@ -1621,7 +1621,6 @@ function formatWithOptions(inspectOptions, ...args) {
tempStr = inspect(args[++a], inspectOptions);
break;
case 111: // 'o'
{
tempStr = inspect(args[++a], {
...inspectOptions,
showHidden: true,
@ -1629,7 +1628,6 @@ function formatWithOptions(inspectOptions, ...args) {
depth: 4
});
break;
}
case 105: // 'i'
const tempInteger = args[++a];
if (typeof tempInteger === 'bigint') {
@ -1648,6 +1646,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;

View File

@ -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 (anonymous)]');
// %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;