Skip to content

Pure Python JSON decoder reports the error position one character past an invalid escape #162028

Open

Description

@thejesh23

Bug report

Bug description:

For an invalid \escape in a string, the pure Python decoder reports the position of the character after the backslash. The C decoder reports the position of the backslash.

from test.support import import_helper

cjson = import_helper.import_fresh_module("json", fresh=["_json"])
pyjson = import_helper.import_fresh_module("json", blocked=["_json"])

for json in cjson, pyjson:
    try:
        json.loads('"\\a"')
    except ValueError as e:
        print(e.pos)
# C: 1
# Python: 2

This is the same kind of difference that gh-154936 fixed for control characters.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

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