Skip to content

fix: preserve negative zero through serialization round-trip - #240

Open
draarivpatel-ui wants to merge 1 commit into
yahoo:mainfrom
draarivpatel-ui:fix/negative-zero-roundtrip
Open

draarivpatel-ui wants to merge 1 commit into
yahoo:mainfrom
draarivpatel-ui:fix/negative-zero-roundtrip

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Fixes #234.

serialize(-0) emitted 0 because JSON.stringify stringifies negative zero as positive zero and the library only used placeholders for NaN/Infinity/-Infinity. This change detects -0 via the replacer's original value (this[key], before toJSON), emits a dedicated placeholder, and replaces it with the literal -0.

Nested values work too: serialize({ t: -0 }) now returns {"t":-0}, and both round-trip with Object.is(..., -0) === true.

Regular 0 is unchanged, and the escape/space/unsafe paths are unaffected.

Test: npm test - 122/122 passing (3 new tests).

Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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.

serialize(-0) returns "0" - negative zero is lost on round-trip

2 participants