Skip to content

Produces invalid JSON when keys/values contain escaped double quotes #32

@Mesoptier

Description

@Mesoptier

For example, consider the following JSON:

{ "this \"key\" is valid": "this \"value\" is valid" }

With limit: 0, this would result in the following JS:

module.exports = JSON.parse(`{"this \"key\" is valid":"this \"value\" is valid"}`)

However, trying to evaluate this JS results in a syntax error:

Uncaught SyntaxError: Unexpected token k in JSON at position 8
    at JSON.parse (<anonymous>)
    at <anonymous>:1:6

The error is correct. Since the quotes are only escaped once, they "appear" escaped to the template string but unescaped to the JSON parser, resulting in a syntax error.

Properly escaped it would look something like this:

module.exports = JSON.parse('{"this \\"key\\" is valid":"this \\"value\\" is valid"}')

I will open a pull request to fix this issue and add test cases.

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