rison-node
rison-node copied to clipboard
Some valid keys of objects produce invalid rison (e.g. `1e3`, `0x99`, `9007199254740993`)
Example:
const obj = {
'153': 153,
'1000': 1000,
'0.5': 0.5,
'-1': -1,
'1e3': 1000,
'0x99': 153,
'9007199254740993': 9007199254740992,
'9007199254740992': 9007199254740992,
}
const encoded = rison.encode(obj);
// (-1:-1,0.5:0.5,0x99:153,1000:1000,153:153,1e3:1000,9007199254740992:9007199254740992,9007199254740993:9007199254740992)
console.log(encoded);
// rison parser error: missing ':'
// error: Uncaught (in promise) Error: rison decoder error: missing ':'
const decoded = rison.decode(encoded);
console.log(decoded);
This is because the current check accounts for infinities, non-numeric keys, and NaN, but it doesn't check that the numeric value is a valid Rison key or that it's round-trippable:
https://github.com/w33ble/rison-node/blob/beffed9ed3ea6c94904041820373f108ee545f5b/js/rison.js#L192