summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-private/private-json-hooks.cc1
-rw-r--r--test/libapt/json_test.cc16
2 files changed, 17 insertions, 0 deletions
diff --git a/apt-private/private-json-hooks.cc b/apt-private/private-json-hooks.cc
index b61829cbf..ce1665b18 100644
--- a/apt-private/private-json-hooks.cc
+++ b/apt-private/private-json-hooks.cc
@@ -79,6 +79,7 @@ class APT_HIDDEN JsonWriter
void popState()
{
this->state = old_states.top();
+ old_states.pop();
}
public:
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());
+}