Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLJS implementation does not parse longs properly #201

Open
prook opened this issue Jan 30, 2020 · 0 comments
Open

CLJS implementation does not parse longs properly #201

prook opened this issue Jan 30, 2020 · 0 comments

Comments

@prook
Copy link

prook commented Jan 30, 2020

When using bidi for client-side routing, [long :param] can be parsed incorrectly, because bidi uses js/Number to parse the parameter. Since JS numbers are double precision floats, it is only possible to store integer values in ±2^53 range. When using large long (as in 64-bit integer) values, the following loss of precision silently occurs:

(bidi.bidi/match-route [[[long :val]] :uh-oh] "9223372036854775807")
=> {:route-params {:val 9223372036854776000}, :handler :uh-oh}

This is confusing, dangerous, and can be easily missed.

Possible solutions:

  • Use goog.math.Long instead of js/Number to prevent precision loss,
  • add some kind of range checking when parsing the param, or check something like
    (= (goog.math.Long. val) (goog.math.Long. (js/Number val)) to at least warn about precision loss, or
  • remove support for long coercion and let people know it's their responsibility to parse their numbers.
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

No branches or pull requests

1 participant