[JSON] fix bug that incorrectly allowed trailing commas after an empty container (#33158)

pull/33163/head
Mark D. Roth 2 years ago committed by GitHub
parent 9c59671936
commit ba1b8b15ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/core/lib/json/json_reader.cc
  2. 2
      test/core/client_channel/lb_policy/xds_override_host_lb_config_parser_test.cc
  3. 6
      test/core/json/json_test.cc

@ -476,6 +476,7 @@ JsonReader::Status JsonReader::Run() {
return Status::GRPC_JSON_PARSE_ERROR; return Status::GRPC_JSON_PARSE_ERROR;
} }
state_ = State::GRPC_JSON_STATE_VALUE_END; state_ = State::GRPC_JSON_STATE_VALUE_END;
container_just_begun_ = false;
EndContainer(); EndContainer();
if (stack_.empty()) { if (stack_.empty()) {
state_ = State::GRPC_JSON_STATE_END; state_ = State::GRPC_JSON_STATE_END;

@ -193,7 +193,7 @@ TEST(XdsOverrideHostConfigParsingTest, ReportsChildPolicyShouldBeArray) {
" \"loadBalancingConfig\":[{\n" " \"loadBalancingConfig\":[{\n"
" \"xds_override_host_experimental\":{\n" " \"xds_override_host_experimental\":{\n"
" \"childPolicy\":{\n" " \"childPolicy\":{\n"
" \"grpclb\":{},\n" " \"grpclb\":{}\n"
" }\n" " }\n"
" }\n" " }\n"
" }]\n" " }]\n"

@ -202,7 +202,7 @@ TEST(Json, Keywords) {
void RunParseFailureTest(const char* input) { void RunParseFailureTest(const char* input) {
gpr_log(GPR_INFO, "parsing string \"%s\" - should fail", input); gpr_log(GPR_INFO, "parsing string \"%s\" - should fail", input);
auto json = JsonParse(input); auto json = JsonParse(input);
EXPECT_FALSE(json.ok()); EXPECT_FALSE(json.ok()) << "input: \"" << input << "\"";
} }
TEST(Json, InvalidInput) { TEST(Json, InvalidInput) {
@ -213,6 +213,10 @@ TEST(Json, InvalidInput) {
RunParseFailureTest("fals"); RunParseFailureTest("fals");
RunParseFailureTest("0,0 "); RunParseFailureTest("0,0 ");
RunParseFailureTest("\"foo\",[]"); RunParseFailureTest("\"foo\",[]");
RunParseFailureTest("{\"field\": {},}");
RunParseFailureTest("[{},]");
RunParseFailureTest("{\"field\": [],}");
RunParseFailureTest("[[],]");
} }
TEST(Json, UnterminatedString) { RunParseFailureTest("\"\\x"); } TEST(Json, UnterminatedString) { RunParseFailureTest("\"\\x"); }

Loading…
Cancel
Save