From ecc86555830148fe4fd30515b6e0ea5226a48c7a Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Wed, 31 Jan 2024 21:29:08 -0500 Subject: [PATCH] Fixed Bad Attachment Web/API Error; refs #168 --- apprise_api/api/tests/test_attachment.py | 4 ++++ apprise_api/api/utils.py | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apprise_api/api/tests/test_attachment.py b/apprise_api/api/tests/test_attachment.py index 6906f84..023dd9d 100644 --- a/apprise_api/api/tests/test_attachment.py +++ b/apprise_api/api/tests/test_attachment.py @@ -283,6 +283,10 @@ class AttachmentTests(SimpleTestCase): with self.assertRaises(ValueError): parse_attachments(attachment_payload, {}) + # We allow empty entries, this is okay; there is just nothing + # returned at the end of the day + assert parse_attachments({''}, {}) == [] + # We can't parse entries that are not base64 but specified as # though they are attachment_payload = { diff --git a/apprise_api/api/utils.py b/apprise_api/api/utils.py index cd15fba..195976e 100644 --- a/apprise_api/api/utils.py +++ b/apprise_api/api/utils.py @@ -178,7 +178,6 @@ class HTTPAttachment(A_MGR['http']): 'Could not prepare {} attachment in {}'.format( filename, settings.APPRISE_ATTACH_DIR)) - # Prepare our item super().__init__(name=filename, **kwargs) @@ -272,6 +271,14 @@ def parse_attachments(attachment_payload, files_request): # Prepare our Attachment # if isinstance(entry, str): + if not entry.strip(): + # ignore blank entries; these can come from using the + # api/website and submitting without an element defined. + # There is no need have a bad outcome; just decrement our + # counter and move along + count -= 1 + continue + if not re.match(r'^https?://.+', entry[:10], re.I): # We failed to retrieve the product raise ValueError(