Skip to content

fix(ini): quote ambiguous string values in stringify to preserve round-trip type#7182

Open
LeSingh1 wants to merge 1 commit into
denoland:mainfrom
LeSingh1:fix/ini-stringify-quote-ambiguous-strings
Open

fix(ini): quote ambiguous string values in stringify to preserve round-trip type#7182
LeSingh1 wants to merge 1 commit into
denoland:mainfrom
LeSingh1:fix/ini-stringify-quote-ambiguous-strings

Conversation

@LeSingh1

Copy link
Copy Markdown

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:

stringify({ key: "true" })  // produces: key=true
parse("key=true")           // returns:  { key: true }  (boolean, not string)

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.

…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
@github-actions github-actions Bot added the ini label Jun 12, 2026
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.57%. Comparing base (cdf74a8) to head (15ed008).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ini file string value containing value that parses as non-string stringifies without quotes

1 participant