Prevent % characters in formatted object output from being re-interpreted as format specifiers.
Problem
When %o or %O formats an object containing % in its keys or values, the stringified output is passed directly into args[0]. The downstream logger (util.formatWithOptions in Node.js, or console.log in browsers) then re-scans the formatted string for %s, %d, %j, etc. specifiers found inside the already-formatted object, consuming subsequent arguments and producing garbled output.
Instead of inlining the formatter output directly into args[0] and removing the original argument, we now replace the original argument in-place with the formatted string and substitute %s as a placeholder in the format string. This delegates the final substitution to the downstream logger (util.formatWithOptions / console.log), which processes %s by consuming the next argument — the pre-formatted string — without re-scanning its contents for additional specifiers.
This is a minimal change (3 lines replaced) that preserves backward compatibility with all existing format specifiers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevent % characters in formatted object output from being re-interpreted as format specifiers.
Problem
When %o or %O formats an object containing % in its keys or values, the stringified output is passed directly into args[0]. The downstream logger (util.formatWithOptions in Node.js, or console.log in browsers) then re-scans the formatted string for %s, %d, %j, etc. specifiers found inside the already-formatted object, consuming subsequent arguments and producing garbled output.
For example:
Solution
Instead of inlining the formatter output directly into args[0] and removing the original argument, we now replace the original argument in-place with the formatted string and substitute %s as a placeholder in the format string. This delegates the final substitution to the downstream logger (util.formatWithOptions / console.log), which processes %s by consuming the next argument — the pre-formatted string — without re-scanning its contents for additional specifiers.
This is a minimal change (3 lines replaced) that preserves backward compatibility with all existing format specifiers.
Test Plan
Fixes #766
Fixes #687