diff options
author | Sergei Krivonos <sergei.krivonos@mariadb.com> | 2021-11-12 03:36:10 +0200 |
---|---|---|
committer | Sergei Krivonos <sergei.krivonos@mariadb.com> | 2021-11-12 03:36:10 +0200 |
commit | a096ed313dcbf64943a77b7cb4c24ed55fb78c84 (patch) | |
tree | 77ad61d4ebf0a750177cfaa08bd830c6abd40fc7 | |
parent | c5380c30b59da88bba2a6394c7599a420016ccdd (diff) | |
download | mariadb-git-bb-10.4-MDEV-16462.tar.gz |
MDEV-16462: add assert to detect duplicated JSON keysbb-10.4-MDEV-16462
-rw-r--r-- | sql/my_json_writer.cc | 16 | ||||
-rw-r--r-- | sql/my_json_writer.h | 4 |
2 files changed, 20 insertions, 0 deletions
diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc index 8e35b25b822..a14e0f70dbe 100644 --- a/sql/my_json_writer.cc +++ b/sql/my_json_writer.cc @@ -19,6 +19,8 @@ #include "my_json_writer.h" #if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) +#include <iostream> + bool Json_writer::named_item_expected() const { return named_items_expectation.size() @@ -60,6 +62,7 @@ void Json_writer::start_object() document_start= false; #if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) got_name= false; + named_items.emplace(); #endif } @@ -95,6 +98,8 @@ void Json_writer::end_object() named_items_expectation.pop_back(); VALIDITY_ASSERT(!got_name); got_name= false; + VALIDITY_ASSERT(named_items.size()); + named_items.pop(); #endif indent_level-=INDENT_SIZE; if (!first_child) @@ -140,7 +145,18 @@ Json_writer& Json_writer::add_member(const char *name, size_t len) } #if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) if (!fmt_helper.is_making_writer_calls()) + { + VALIDITY_ASSERT(!got_name); got_name= true; + auto& named_items_keys= named_items.top(); + auto emplaced= named_items_keys.emplace(name, len); + auto is_uniq_key= emplaced.second; + if(!is_uniq_key) + { + std::cerr << "Duplicated key: " << *emplaced.first << std::endl; + VALIDITY_ASSERT(is_uniq_key); + } + } #endif return *this; } diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index 7d209501a87..529e483e150 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -18,6 +18,9 @@ #include "my_base.h" #if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) +#include <set> +#include <stack> +#include <string> #include <vector> #endif @@ -209,6 +212,7 @@ class Json_writer produce an invalid JSON document (e.g. JSON array having named elements). */ std::vector<bool> named_items_expectation; + std::stack<std::set<std::string> > named_items; bool named_item_expected() const; |