Skip to content

bug(StdJson): escaped characters are not parsed correctly #332

@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

    bugSomething isn't workingdependentRequires upstream support

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions