Skip to content

fix(hmget): preserve unsafe integers in HMGET, HGETEX and HGETDEL - #1485

Open
pcbeingused333 wants to merge 1 commit into
upstash:mainfrom
pcbeingused333:fix/hmget-unsafe-integer
Open

pcbeingused333 wants to merge 1 commit into
upstash:mainfrom
pcbeingused333:fix/hmget-unsafe-integer

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Root cause. HMGetCommand parsed each hash field with parseJSON and kept the number even when it could not be represented exactly. A stored 9007199254740993 came back as 9007199254740992. HGETEX and HGETDEL use that same helper. HGET and the default command parser already return the original string for this case, via parseResponse.

Fix. Present fields now go through parseResponse. A null field stays null. A leading BOM is still removed when the value parses cleanly, and remains on the original string when the integer would be rounded. The shared parser also keeps the original text when toString() does not match it (a stored 1.0 stays "1.0"), which is how HGET already behaves.

Test. hmget-deserialize.test.ts calls deserialize on HMGET, HGETEX and HGETDEL with no Redis server. On main the four unsafe-integer cases fail. With this change all six tests pass, including null fields, ordinary JSON, the decimal 1.5, a safe integer and a BOM-prefixed safe number. A changeset is included.


Disclosure: this change was prepared with AI assistance.

Route present hash fields through parseResponse so an integer JSON.parse
cannot represent stays the original string. Null fields stay null. HGETEX
and HGETDEL share this helper.

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant