Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 3 tasks
JinLiOnline opened this issue Nov 27, 2024 · 1 comment
Closed
1 of 3 tasks

Comments

@JinLiOnline
Copy link

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
@danielaparker
Copy link
Owner

Thanks for reporting this. It should be fixed on master.

@danielaparker danielaparker changed the title json_string_reader doesnot work correctly for empty string or string with all blanks json_string_reader does not work correctly for empty string or string with all blanks Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants