Skip to content

The library parsed an invalid json string successfully which should report an error when parsing #720

@MatthewButterfly

Description

@MatthewButterfly

Here I have a string as below which I think should not be an valid json.
But it is parsed successfull and there are no errors reported when using function parse() to parse.

6?h??^M^V??P/.ׇ?%4602053579,"is^Soffline":"1","account_id":"","msg_id":"A"}

Below is the code I used.

 

1.    std::string str = "6?h??^M^V??P/.ׇ?%4602053579,\"is^Soffline\":\"1\",\"account_id\":\"\",\"msg_id\":\"A\"}";
2. 
3.     Json::Value obj;
4.     Json::Reader reader;
5.     Json::FastWriter writer;
6. 
7.     if(!reader.parse(str,obj))
8.     {
9.        cout << "parse error.\n";
10.     }
11. 
12.     try {
13.         std::string test = obj["msg_id"].asString();
14.         cout << test;
15.     } catch (const std::exception& err) {
16.         cout << "error : " <<  err.what() << endl;
17.     }

I think the code should go into the if block and type the error. But it didn't.
The code skiped the line 9 and go into line 13 directly and threw an exception.

Below is the output.

error : in Json::Value::resolveReference(key, end): requires objectValue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions