Skip to content

Port round-trip bug fixes from Python ZON PR#9 to TypeScript#3

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/sync-with-other-package
Open

Port round-trip bug fixes from Python ZON PR#9 to TypeScript#3
Copilot wants to merge 3 commits into
mainfrom
copilot/sync-with-other-package

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

  • Confirm top-level objects bypass _formatZonNode/_parseKey code paths
  • Update boolean-keys.test.ts: wrap fixtures in { wrapper: {...} } so tests exercise the patched code paths
  • Replaced broken mixed-key array test with a multi-sibling-object test
  • All 311 tests pass

Copilot AI and others added 2 commits April 23, 2026 20:02
Agent-Logs-Url: https://github.com/ZON-Format/zon-TS/sessions/e5aab0b1-0f14-4a0f-bb3d-279a7a7bf62b

Co-authored-by: ronibhakta1 <77425964+ronibhakta1@users.noreply.github.com>
- Fix 1 (encoder): Quote boolean/null keyword keys (t, f, true, false,
  null, none, nil) in _formatZonNode to prevent round-trip corruption
- Fix 2 (decoder): Add parseKey() that always preserves keys as strings,
  replacing parseValue() at all key-parsing call sites
- Fix 3 (encoder): Quote dictionary header values that contain commas or
  other special characters using _formatValue()
- Fix 4 (decoder): Use _splitByDelimiter() + _parseValue() for dictionary
  header value parsing instead of naive vals.split(',')
- Add tests: boolean-keys.test.ts and dict-header-quoting.test.ts

Agent-Logs-Url: https://github.com/ZON-Format/zon-TS/sessions/e5aab0b1-0f14-4a0f-bb3d-279a7a7bf62b

Co-authored-by: ronibhakta1 <77425964+ronibhakta1@users.noreply.github.com>
@ronibhakta1
Copy link
Copy Markdown
Contributor

@coderabbitai look into this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

@ronibhakta1 Sure! I'll start reviewing this PR now. I'll look into the three round-trip bug fixes ported from the Python ZON implementation — boolean-like dictionary keys, dictionary header value quoting, and the associated test coverage. I'll post my findings shortly.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

This PR adds test coverage and implementation improvements for ZON encoding/decoding edge cases, including boolean-like dictionary keys and special characters in headers. A new parseKey utility function distinguishes key parsing from value parsing, with updates to encoder and decoder accordingly.

Changes

Cohort / File(s) Summary
Test Coverage
src/__tests__/boolean-keys.test.ts, src/__tests__/dict-header-quoting.test.ts
New Jest test suites validating encoding/decoding of boolean-like dictionary keys ("true", "false", "null", etc.) and dictionary headers containing commas and colons, ensuring round-trip preservation of original string keys and field values.
Key Parsing Utility
src/core/utils.ts
Introduces parseKey function for ZON dictionary keys that always returns strings, supporting double-quoted and single-quoted keys, with ZON-to-JSON escape sequence conversion, without boolean/null keyword conversion.
Decoder Key Handling
src/core/decoder.ts
Updates key parsing to use _parseKey instead of _parseValue, and enhances dictionary handling by splitting and parsing dictionary values with awareness of quotes and nesting.
Encoder Key Quoting
src/core/encoder.ts
Adds quoting of object keys that resemble boolean/null keywords (true/false/t/f/null/none/nil, case-insensitive) to prevent misinterpretation; formats dictionary string values via _formatValue before emission.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Keys and values, quite the pair!
We parse them with the utmost care.
No more "true" masquerading as a fact,
Each quoted key stays on its track.
Boolean-like keys now round-trip true,
The ZON encoder/decoder's breakthrough! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main objective of the PR: porting round-trip bug fixes from the Python ZON implementation to TypeScript, which aligns with the substantial changes across encoder, decoder, and utilities.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch copilot/sync-with-other-package

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ronibhakta1 ronibhakta1 marked this pull request as ready for review April 27, 2026 21:09
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/__tests__/boolean-keys.test.ts (1)

12-98: Broaden these cases to hit the new parser path.

The top-level scalar fixtures still serialize through metadata lines, so they won't fail if _formatZonNode / _parseKey regresses. Consider moving the boolean-like keys under an object-valued property, or into an array-of-objects fixture, so these tests actually cover the fix.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/__tests__/boolean-keys.test.ts` around lines 12 - 98, The tests currently
encode top-level scalar objects so they bypass the new parser path; change each
fixture to place the boolean-like keys inside an object-valued property (e.g.
const data = { wrapper: { f: 1 } }) or into an array of objects (e.g. const data
= { items: [{ f: 1 }] }) so encode/decode passes through the zone-node
formatting/parsing code paths (those exercised by _formatZonNode / _parseKey);
update the assertions to inspect decoded.wrapper.f or decoded.items[0].f (and
corresponding keys like 'true','false','null') and adjust the case-variant loop
and multi-key test similarly so they validate nested/object-array decoded values
instead of top-level keys.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/__tests__/boolean-keys.test.ts`:
- Around line 12-98: The tests currently encode top-level scalar objects so they
bypass the new parser path; change each fixture to place the boolean-like keys
inside an object-valued property (e.g. const data = { wrapper: { f: 1 } }) or
into an array of objects (e.g. const data = { items: [{ f: 1 }] }) so
encode/decode passes through the zone-node formatting/parsing code paths (those
exercised by _formatZonNode / _parseKey); update the assertions to inspect
decoded.wrapper.f or decoded.items[0].f (and corresponding keys like
'true','false','null') and adjust the case-variant loop and multi-key test
similarly so they validate nested/object-array decoded values instead of
top-level keys.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 28649438-7a7e-46bc-a7af-8000e6ec5b5c

📥 Commits

Reviewing files that changed from the base of the PR and between 1b5917d and e60b76d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • src/__tests__/boolean-keys.test.ts
  • src/__tests__/dict-header-quoting.test.ts
  • src/core/decoder.ts
  • src/core/encoder.ts
  • src/core/utils.ts

…_formatZonNode/_parseKey paths

Per coderabbitai review: top-level `{ f: 1 }` encoded as implicit KV (f:1)
and bypassed the _formatZonNode / _parseKey code paths. Updated all fixtures
to `{ wrapper: { keyword: 1 } }` so encode produces `wrapper{"keyword":1}`,
going through the patched code. Also replaced a broken array-of-mixed-keys
test with a multi-sibling-object test that encodes via _formatZonNode.

Agent-Logs-Url: https://github.com/ZON-Format/zon-TS/sessions/d685654f-1fcf-4efb-892d-ca37bbc8657e

Co-authored-by: ronibhakta1 <77425964+ronibhakta1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants