Fix invalid imports in [{..}] form (#3241)

* Fix invalid imports in `[{..}]` form

Before this change, if an import of data that takes the form of a JSON
array of JSON objects results in an error, the import would be re-tried
assuming that each line of the file is a JSON object (the old format).
However, no check was made that the value actually was an object before
casting it to `json::object`, resulting in a segfault.

This adds the check, and handles the failure with a useful error message
(from the first attempt to parse the file).
This commit is contained in:
Dustin J. Mitchell 2024-01-25 08:01:20 -05:00 committed by GitHub
parent 5b5a7a37c0
commit 83bbe4ec37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 7 deletions

View file

@ -279,6 +279,12 @@ class TestImportValidate(TestCase):
code, out, err = self.t.runError("import", input=j)
self.assertIn("Not a valid UUID", err)
def test_import_invalid_uuid_array(self):
"""Verify invalid UUID is caught in array form"""
j = '[{"uuid":"1", "description":"bad"}]'
code, out, err = self.t.runError("import", input=j)
self.assertIn("Not a valid UUID", err)
def test_import_invalid_uuid2(self):
"""Verify invalid UUID is caught, part two"""
# UUID is the right length, but with s/-/0/.