dyedgreen / deno-sqlite

Deno SQLite module
https://deno.land/x/sqlite
MIT License
409 stars 36 forks source link

Fix binding of +Infinity, -Infinity, -0, and extremely large number values #91

Closed jeremyBanks closed 3 years ago

jeremyBanks commented 3 years ago

Closes #89

Fixes and adds tests the incorrect binding of +Infinity, -Infinity, -0, and extremely-large number values, by only binding to INTEGER for values which satisfy (Number.isSafeInteger(value) && !Object.is(value, -0)), instead of (Math.floor(value) === value).

In order to be preserve -0, we have to bind it as a REAL instead of an INTEGER like +0. As far as I can tell, this should be harmless.

A change in behaviour to call out: integer number values more massive than MAX_SAFE_INTEGER which could fit into an INTEGER will now be stored as REAL instead of INTEGER. I could go either way on this, but settled with this because you're usually not supposed to be treating values larger than MAX_SAFE_INTEGER as integers, even if they happen to fall on integer values.

If you want to maintain them as INTEGER, I think you could change the condition to something like (Number.isFinite(value) && !Object.is(value, -0) && Math.floor(value) === value && -9_223_372_036_854_775_808 <= value && value <= 9_223_372_036_854_775_807) instead.

dyedgreen commented 3 years ago

LGTM 😍

Thank you @jeremyBanks for flagging this issue and the quick fix!