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:
parent
8f06773a8c
commit
8235ffd786
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user