From 09e3c0c855e339216784a1d43715c3ae2d79ec23 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 21 Apr 2021 12:17:55 +0200 Subject: json: Actually pop states The JSON encoder only looked at the top state, but did not pop it, so if we nested objects, we got stuck in whatever the last state we pushed aside was, so in our example, we wrongly get a comma inserted _after_ key "b": {"a":[{}], "b":,[{}] } --- test/libapt/json_test.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/libapt/json_test.cc') diff --git a/test/libapt/json_test.cc b/test/libapt/json_test.cc index e3317afc4..9c29936f6 100644 --- a/test/libapt/json_test.cc +++ b/test/libapt/json_test.cc @@ -43,3 +43,19 @@ TEST(JsonTest, JsonArrayAndValues) EXPECT_EQ("[0,\"value\",1,true]", os.str()); } +TEST(JsonTest, JsonStackRegression) +{ + std::ostringstream os; + + JsonWriter w(os); + + // Nest those things deeply such that we transition states: + // object -> array -> object; -> array -> object + // Older versions never popped back and got stuck on array state. + w.beginObject(); + w.name("a").beginArray().beginObject().endObject().endArray(); + w.name("b").beginArray().beginObject().endObject().endArray(); + w.endObject(); + + EXPECT_EQ("{\"a\":[{}],\"b\":[{}]}", os.str()); +} -- cgit v1.2.3-70-g09d2