Skip to content

loads() accepts any character in an unquoted key when it is written as a \u escape #161

Closed

Description

@simonvanlierde

Hi!

json5.loads does not check the character behind a \uXXXX escape in an unquoted key, so keys the spec forbids are accepted:

import json5

json5.loads(r"{\u0301: 1}")    # a combining mark as the first character
json5.loads(r"{\u002d: 1}")    # {'-': 1}
json5.loads(r"{a\u0020b: 1}")  # {'a b': 1}

JSON5 §3 takes unquoted keys from ECMAScript 5.1 §7.6, which says a UnicodeEscapeSequence in an IdentifierName cannot put a character there that would be illegal if written literally. The same keys written literally ({-: 1}, {a b: 1}) are rejected, and the reference json5 for JavaScript (2.2.3) rejects {\u0301: 1} and {\u002d: 1}.

I found this while running a set of JSON5 test files through several parsers. Tested with json5 0.17.3 on Python 3.14.

Best,

Simon

Activity

  1. dpranke commented on Nov 11, 2026

    @dpranke
    Owner

    Hi! thanks for the bug report :).

    In perhaps good news, I think this was fixed with PR #125 on trunk, which hasn't been released yet (along w/ a slew of other fixes), and your examples all fail on trunk, so I'm closing this. It should be closed as a duplicate, but I don't think a bug was fixed for that, just the PR.

  2. dpranke commented on Nov 11, 2026

    @dpranke
    Owner

    If you're still seeing issues on trunk, please feel free to re-open this. If you're trying to do a bunch of conformance testing, or, as you said, just comparing implementations, please use the latest code on trunk if you can to verify things are still issues.

    Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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