diff --git a/InvenTree/barcode/plugins/inventree_barcode.py b/InvenTree/barcode/plugins/inventree_barcode.py index 6e4e6937a0..93fb58cbc0 100644 --- a/InvenTree/barcode/plugins/inventree_barcode.py +++ b/InvenTree/barcode/plugins/inventree_barcode.py @@ -42,6 +42,8 @@ class InvenTreeBarcodePlugin(BarcodePlugin): elif type(self.data) is str: try: self.data = json.loads(self.data) + if type(self.data) is not dict: + return False except json.JSONDecodeError: return False else: diff --git a/InvenTree/barcode/tests.py b/InvenTree/barcode/tests.py index 98e126eba1..4b7356aead 100644 --- a/InvenTree/barcode/tests.py +++ b/InvenTree/barcode/tests.py @@ -56,6 +56,34 @@ class BarcodeAPITest(APITestCase): self.assertIn('plugin', data) self.assertIsNone(data['plugin']) + def test_integer_barcode(self): + + response = self.postBarcode(self.scan_url, '123456789') + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.data + self.assertIn('error', data) + + self.assertIn('barcode_data', data) + self.assertIn('hash', data) + self.assertIn('plugin', data) + self.assertIsNone(data['plugin']) + + def test_array_barcode(self): + + response = self.postBarcode(self.scan_url, "['foo', 'bar']") + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.data + self.assertIn('error', data) + + self.assertIn('barcode_data', data) + self.assertIn('hash', data) + self.assertIn('plugin', data) + self.assertIsNone(data['plugin']) + def test_barcode_generation(self): item = StockItem.objects.get(pk=522)