Skip to content

Strings with leading 0s are accepted but produce invalid JSON #6

@eug48

Description

@eug48

i.e.

const bignumJSON = require('json-bignum')

> bignumJSON.stringify({key: new bignumJSON.BigNumber("0123")})
'{"key":0123}'

> JSON.parse(bignumJSON.stringify({key: new bignumJSON.BigNumber("0123")}))
SyntaxError: Unexpected number in JSON at position 8

I know the bug is mainly in the code using json-bignum but by allow invalid JSON to be produced the bug is allowed to propagate into other systems.. Perhaps strings with leading 0s should be rejected with an exception in the BigNumber constructor?

throw new Error(number + ' is not a number');

BTW, thanks very much for this simple & effective package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions