Skip to content

json_string_reader does not work correctly for empty string or string with all blanks #561

@JinLiOnline

Description

@JinLiOnline

Describe the bug

https://github.com/danielaparker/jsoncons/blob/master/doc/Examples.md#validate-json-without-incurring-parse-exceptions

We use "json_string_reader" to verify the validity of JSON. However, for some strings(e.g. empty string, string with all blanks, \t \n ), no error is reported.

Enumerate the steps to reproduce the bug

std::vector<std::string> vec{"", "  ", "  \t  ", " \n "};
for(const auto& str : vec) {
    jsoncons::json_string_reader reader(str);
    std::error_code ec;
    reader.read(ec);
    reader.check_done();

    if (ec) {
        std::cout << ec.message() << " ";
    } else {
        std::cout << "OK ";
    }

    try {
        jsoncons::json::parse(str);
        std::cout << "OK ";
    } catch (...) {
        std::cout << "err ";
    }

    std::cout << "\n";
}

What is the expected behavior?
The expected result is that the "json_string_reader" can return an error.

What jsoncons library version?

  • Latest release 0.178.0
  • Other release ______
  • master

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions