Skip to content

Conversation

@MeetInCode
Copy link

Linked Issue

Closes #249

Description

Fixed a bug where strings starting with . or + followed by numbers (e.g., ".622", "+861") were incorrectly identified as safe to encode without quotes. This caused them to be encoded as raw numeric-like tokens (e.g., .622, +861), which could be misinterpreted as numbers during decoding in some environments or by other parsers.

The fix expands the numeric detection pattern to ensure these ambiguous strings are explicitly quoted in the output.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Changes Made

  • Updated NUMERIC_LIKE_PATTERN regex in packages/toon/src/shared/validation.ts to include patterns starting with . (optional digits before) and explicit + signs.
  • Added a regression test packages/toon/test/issue-249.test.ts to verify that string values like ".622..." and "+861..." are now properly quoted.

SPEC Compliance

  • This PR implements/fixes spec compliance
  • Spec section(s) affected:
  • Spec version:

Testing

  • All existing tests pass
  • Added new tests for changes
  • Tests cover edge cases and spec compliance

Verified the fix with the new regression test:

const data = ['.6226633103089010', '+8613334445577']
// Encoded output is now: [".6226633103089010", "+8613334445577"]
// Previously was: [.6226633103089010, +8613334445577]

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.

Data deserialization is unequal

2 participants