Skip to content

Commit

Permalink
[JSON] fix bug that incorrectly allowed trailing commas after an empt…
Browse files Browse the repository at this point in the history
…y container (#33158)
  • Loading branch information
markdroth authored and wanlin31 committed May 18, 2023
1 parent ad9ced6 commit fe1a232
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/lib/json/json_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ JsonReader::Status JsonReader::Run() {
return Status::GRPC_JSON_PARSE_ERROR;
}
state_ = State::GRPC_JSON_STATE_VALUE_END;
container_just_begun_ = false;
EndContainer();
if (stack_.empty()) {
state_ = State::GRPC_JSON_STATE_END;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ TEST(XdsOverrideHostConfigParsingTest, ReportsChildPolicyShouldBeArray) {
" \"loadBalancingConfig\":[{\n"
" \"xds_override_host_experimental\":{\n"
" \"childPolicy\":{\n"
" \"grpclb\":{},\n"
" \"grpclb\":{}\n"
" }\n"
" }\n"
" }]\n"
Expand Down
6 changes: 5 additions & 1 deletion test/core/json/json_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ TEST(Json, Keywords) {
void RunParseFailureTest(const char* input) {
gpr_log(GPR_INFO, "parsing string \"%s\" - should fail", input);
auto json = JsonParse(input);
EXPECT_FALSE(json.ok());
EXPECT_FALSE(json.ok()) << "input: \"" << input << "\"";
}

TEST(Json, InvalidInput) {
Expand All @@ -213,6 +213,10 @@ TEST(Json, InvalidInput) {
RunParseFailureTest("fals");
RunParseFailureTest("0,0 ");
RunParseFailureTest("\"foo\",[]");
RunParseFailureTest("{\"field\": {},}");
RunParseFailureTest("[{},]");
RunParseFailureTest("{\"field\": [],}");
RunParseFailureTest("[[],]");
}

TEST(Json, UnterminatedString) { RunParseFailureTest("\"\\x"); }
Expand Down

0 comments on commit fe1a232

Please sign in to comment.