fix(ini): quote ambiguous string values in stringify to preserve round-trip type#7182
Open
LeSingh1 wants to merge 1 commit into
Open
fix(ini): quote ambiguous string values in stringify to preserve round-trip type#7182LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
…d-trip type
When stringifying an object whose values are strings that look like other
types ("true", "false", "null", or a numeric string like "123"), the
default replacer was emitting them bare. The parser then read them back as
boolean, null, or number, silently corrupting the value on a round-trip.
The fix makes defaultReplacer wrap such strings in double quotes, which
parseValue already handles correctly via QUOTED_VALUE_REGEXP.
Closes denoland#4809
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7182 +/- ##
==========================================
- Coverage 94.57% 94.57% -0.01%
==========================================
Files 636 637 +1
Lines 52142 52160 +18
Branches 9401 9408 +7
==========================================
+ Hits 49315 49329 +14
- Misses 2249 2254 +5
+ Partials 578 577 -1 ☔ View full report in Codecov by Harness. 🚀 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 #4809.
When you call stringify on an object whose values are strings that happen
to look like another type, the output loses type information. For example:
The same happens with "false", "null", and any numeric string like "123".
The string is written bare, and parseValue then converts it back to the
wrong type. A round-trip through parse(stringify(obj)) silently changes
"true" to true, "null" to null, "123" to 123, and so on.
The root cause is in defaultReplacer, which just does template literal
interpolation without checking whether the string value would be
misread by parseValue. parseValue already supports double-quoted strings
via QUOTED_VALUE_REGEXP and returns them as-is. So the fix is to have
defaultReplacer wrap the ambiguous strings in double quotes.
Plain strings that cannot be mistaken for another type (like "hello" or
"123foo") are left unquoted as before.
I added assertions for the individual quoted outputs and a round-trip test
covering all the affected cases. All 18 tests pass, deno fmt and deno lint
are clean.