Repository navigation
util: refresh styleText() fast-path cache when inspect colors change - #67989
Open
bunnysayzz wants to merge 1 commit into
Open
bunnysayzz wants to merge 1 commit into
bunnysayzz wants to merge 1 commit into
Conversation
The styleText() fast path builds a cache of util.inspect.colors once in getStyleCache() and never invalidates it, so customizing a color after the first call had no effect on the fast path while the slow path and array format picked it up. Refresh the cached entry for the requested format from the live colors on each call, and drop the entry when the color was removed so the slow path throws as before. Fixes: nodejs#67980 Signed-off-by: bunnysayzz <stfuazzo@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67989 +/- ##
==========================================
- Coverage 90.58% 90.56% -0.03%
==========================================
Files 802 802
Lines 286955 286971 +16
Branches 55404 55418 +14
==========================================
- Hits 259942 259882 -60
- Misses 17115 17165 +50
- Partials 9898 9924 +26
🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #67980
The styleText() fast path builds a cache of util.inspect.colors once in getStyleCache() and never invalidates it, so changing a color after the first call had no effect there, while the slow path and the array format picked it up. This refreshes the cached entry for the requested format from the live colors on each call, and drops the entry when the color was removed so the slow path throws as before.
Verified the fix logic against the issue repro plus edge cases (in-place mutation, new color, deleted color, bold/dim keepClose) with a local harness using the patched functions; the new test fails on the current code and passes with the fix. I could not run the full test suite here since there is no node build on this machine, CI will confirm.
Note: I used an AI assistant to help draft this change.