Closed
Description
When I add the testcase for Reader, I find a bug in
jsoncpp/src/lib_json/json_reader.cpp
Line 470 in d6c4a8f
The testcase is as follows:
JSONTEST_FIXTURE_LOCAL(ReaderTest, allowNumericKeysTest) {
Json::Features features;
features.allowNumericKeys_ = true;
setFeatures(features);
checkParse(R"({ 123 : "abc" })");
}
The result is as follows:
Testing MemberTemplateAs/BehavesSameAsNamedAs: OK
Testing MemberTemplateIs/BehavesSameAsNamedIs: OK
* Detail of ReaderTest/allowNumericKeys test failure:
../src/test_lib_json/jsontest.cpp(244): Unexpected exception caught:
in Json::Value::asCString(): requires stringValue
113/114 tests passed (1 failure(s))
-------
By analyzing related code, I find the asCString() is not a suitable interface for NumericKeys.
const char* Value::asCString() const {
JSON_ASSERT_MESSAGE(type() == stringValue,
"in Json::Value::asCString(): requires stringValue");
if (value_.string_ == nullptr)
return nullptr;
unsigned this_len;
char const* this_str;
decodePrefixedString(this->isAllocated(), this->value_.string_, &this_len,
&this_str);
return this_str;
}
numberName
value is a number value(type is realvalue/uintvalue) and asCString() can not convert the numbervalue to string. We should replace asCString() with asString().
Modift content is shown in #1122
Metadata
Metadata
Assignees
Labels
No labels