diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2021-11-05 20:01:43 +0300 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2021-11-05 20:01:43 +0300 |
commit | 2ddeb16841ff10ee5c4178b6aeee52ee285a2838 (patch) | |
tree | 2a54e0b4ba6e17c8f08f3f2af7b586eedf9cce0e /sql/my_json_writer.h | |
parent | a51ad4ee623648feab1eac5de4b7a3bbd06a3049 (diff) | |
download | mariadb-git-bb-10.5-MDEV-23766.tar.gz |
MDEV-23766: Make Json_writer assert when one tries to author invalid JSONbb-10.5-MDEV-23766
- Add unit test.
Diffstat (limited to 'sql/my_json_writer.h')
-rw-r--r-- | sql/my_json_writer.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index 50b277a5052..6f9ae73c5ee 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -16,7 +16,17 @@ #ifndef JSON_WRITER_INCLUDED #define JSON_WRITER_INCLUDED #include "my_base.h" + +#ifdef JSON_WRITER_UNIT_TEST +#include "sql_string.h" +#include <vector> +// Also, mock objects are defined in my_json_writer-t.cc +#define VALIDITY_ASSERT(x) if ((!x)) this->invalid_json= true; +#else #include "sql_select.h" +#define VALIDITY_ASSERT(x) DBUG_ASSERT(x) +#endif + class Opt_trace_stmt; class Opt_trace_context; class Json_writer; @@ -191,12 +201,22 @@ private: class Json_writer { #ifndef NDEBUG - + /* + In debug mode, Json_writer will fail and assertion if one attempts to + produce an invalid JSON document (e.g. JSON array having named elements). + */ std::vector<bool> named_items_expectation; bool named_item_expected() const; bool got_name; + +#ifdef JSON_WRITER_UNIT_TEST +public: + // When compiled for unit test, creating invalid JSON will set this to true + // instead of an assertion. + bool invalid_json= false; +#endif #endif public: |