Skip to content

ujson dumps NaN but doesn't load it #3511

@stinos

Description

@stinos

The mod_ujson_load function doesn't handle nan though it is a valid representation:

>>> import ujson
>>> ujson.dumps(float('nan'))
'nan'
>>> ujson.loads(ujson.dumps(float('nan')))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: syntax error in JSON

Quick hack to solve this (sorry couldn't immediately figure out how to get the nan constant), line 115 in modujson.c:

                } else if (S_CUR(s) == 'a' && S_NEXT(s) == 'n') {
                    S_NEXT(s);
                    next = mp_parse_num_decimal("nan", 3, false, false, NULL);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions