Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: skip/strip %c formatting #29606

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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') {
Expand All @@ -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;
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 (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;
Expand Down