open-source-parsers / open-source-parsers/jsoncpp
Negative infinity round-trips as invalid JSON
Open
Nobody has claimed this yet.
bug
- Dominant language
- C++
- Stars
- 8.9k
- Forks
- 2.7k
- Avg merge
- 31m
- Merged PRs (30d)
- 1
Description
Describe the bug
inf and -inf don't round trip if useSpecialFloats is false.
To Reproduce
Steps to reproduce the behavior:
Json::Value testJson(Json::arrayValue);
testJson[0] = 25.0;
testJson[1] = 0.0;
testJson[2] = -std::numeric_limits<float>::infinity();
Json::StreamWriterBuilder builder;
builder["indentation"] = "\t";
// both false/true are incorrect
//builder["useSpecialFloats"] = true;
const std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
std::stringstream ss;
writer->write(testJson, &ss);
Json::Reader reader;
Json::Value json;
bool is_valid = reader.parse(ss, json);
// is_valid == false
// errors list -1e+9999 as invalid number
Expected behavior
Should at least parse rather than hard fail.
Desktop (please complete the following information):
- OS: Windows
- Ninja version 1.10.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied reproduction and inspect the Json::StreamWriterBuilder, Json::StreamWriter, and Json::Reader paths involved in serializing and parsing -inf. Done means the emitted value can be parsed without an invalid-number error while preserving the intended round trip.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100