aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/JSON.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libqpdf/JSON.cc')
-rw-r--r--libqpdf/JSON.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc
index 1c49f9ee..a2aff78b 100644
--- a/libqpdf/JSON.cc
+++ b/libqpdf/JSON.cc
@@ -949,17 +949,11 @@ JSONParser::handleToken()
case '{':
item = std::make_shared<JSON>(JSON::makeDictionary());
item->setStart(offset - token.length());
- if (reactor) {
- reactor->dictionaryStart();
- }
break;
case '[':
item = std::make_shared<JSON>(JSON::makeArray());
item->setStart(offset - token.length());
- if (reactor) {
- reactor->arrayStart();
- }
break;
default:
@@ -1187,6 +1181,18 @@ JSONParser::handleToken()
"JSONParser::handleToken: unexpected null item in transition");
}
+ if (reactor && item.get()) {
+ // Calling container start method is postponed until after
+ // adding the containers to their parent containers, if any.
+ // This makes it much easier to keep track of the current
+ // nesting level.
+ if (item->isDictionary()) {
+ reactor->dictionaryStart();
+ } else if (item->isArray()) {
+ reactor->arrayStart();
+ }
+ }
+
// Prepare for next token
if (item.get()) {
if (item->isDictionary()) {