Skip to content

Some valid keys of objects produce invalid rison (e.g. 1e3, 0x99, 9007199254740993) #6

@lionel-rowe

Description

@lionel-rowe

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:

k = !isFinite(i) || isNaN(parseInt(i)) ? s.string(i) : s.number(i)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions