juxt / bidi

Bidirectional URI routing
MIT License
993 stars 90 forks source link

CLJS implementation does not parse longs properly #201

Open prook opened 4 years ago

prook commented 4 years ago

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: