fix Reader bug and add testcase (#1122)

This commit is contained in:
Chen 2019-12-23 10:56:54 +08:00 committed by GitHub
parent d6c4a8fb2d
commit 92d90250f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -467,7 +467,7 @@ bool Reader::readObject(Token& token) {
Value numberName;
if (!decodeNumber(tokenName, numberName))
return recoverFromError(tokenObjectEnd);
name = String(numberName.asCString());
name = numberName.asString();
} else {
break;
}

View File

@ -2648,6 +2648,10 @@ struct ReaderTest : JsonTest::TestCase {
new Json::Reader(Json::Features{}.strictMode()));
}
void setFeatures(Json::Features& features) {
reader = std::unique_ptr<Json::Reader>(new Json::Reader(features));
}
void checkStructuredErrors(
const std::vector<Json::Reader::StructuredError>& actual,
const std::vector<Json::Reader::StructuredError>& expected) {
@ -2851,6 +2855,13 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, pushErrorTest) {
"See Line 1, Column 14 for detail.\n");
}
JSONTEST_FIXTURE_LOCAL(ReaderTest, allowNumericKeysTest) {
Json::Features features;
features.allowNumericKeys_ = true;
setFeatures(features);
checkParse(R"({ 123 : "abc" })");
}
struct CharReaderTest : JsonTest::TestCase {};
JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithNoErrors) {