From 05904549a0693278dba40fccf00043734857e1fc Mon Sep 17 00:00:00 2001 From: Bharatvaj H Date: Sat, 21 Aug 2021 06:24:12 +0530 Subject: [PATCH] Fixes #2580 Check annotations field before parsing Add test case for annotations --- src/Task.cpp | 5 +++++ test/import.t | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/Task.cpp b/src/Task.cpp index cc0316c9d..89f7de6ce 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -793,6 +793,11 @@ void Task::parseJSON (const json::object* root_obj) { std::map annos; + // Fail if 'annotations' is not an array + if (i.second->type() != json::j_array) { + throw format ("Annotations is malformed: {1}", i.second->dump ()); + } + auto atts = (json::array*)i.second; for (auto& annotations : atts->_data) { diff --git a/test/import.t b/test/import.t index eb5b48f42..638db6ed5 100755 --- a/test/import.t +++ b/test/import.t @@ -292,6 +292,12 @@ class TestImportValidate(TestCase): code, out, err = self.t.runError("import", input=j) self.assertIn("The status 'foo' is not valid.", err) + def test_import_malformed_annotation(self): + """Verify invalid 'annnotations' is caught""" + j = '{"description": "bad", "annotations": "bad"}' + code, out, err = self.t.runError("import", input=j) + self.assertIn('Annotations is malformed: "bad"', err) + class TestImportWithoutISO(TestCase): def setUp(self):