Skip to content

escaped characters in json are not parsed correctly #332

Open
@0xkarmacoma

Description

@0xkarmacoma

Repro:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {stdJson} from "forge-std/StdJson.sol";

import "forge-std/Test.sol";

contract JsonTest is Test {
    function testEscapedQuotes() public {
        string memory json = '{"foo":"quotation mark: \'\\"\' and backslash: \\\\"}';

        assertEq(stdJson.readString(json, ".foo"), 'quotation mark: \'"\' and backslash: \\');
    }
}

The test passes with b4f1215 but fails with f8e700e

[FAIL. Reason: Assertion failed.] testEscapedQuotes() (gas: 19525)
Logs:
  Error: a == b not satisfied [string]
    Expected: quotation mark: '"' and backslash: \
      Actual: quotation mark: '\' and backslash: \\

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