Skip to content
Permalink
Browse files

console: skip/strip %c formatting

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 addaleax committed Sep 18, 2019
1 parent 8f06773 commit 8235ffd7863305485dbbe27e7ed8bbe9f369d19d
Showing with 15 additions and 2 deletions.
  1. +5 −0 doc/api/util.md
  2. +4 −2 lib/internal/util/inspect.js
  3. +6 −0 test/parallel/test-util-format.js
@@ -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,15 +1621,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') {
@@ -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;

0 comments on commit 8235ffd

Please sign in to comment.
You can’t perform that action at this time.