Fixed Bad Attachment Web/API Error; refs #168

This commit is contained in:
Chris Caron
2024-01-31 21:29:08 -05:00
parent d556f14d0a
commit ecc8655583
2 changed files with 12 additions and 1 deletions

View File

@@ -283,6 +283,10 @@ class AttachmentTests(SimpleTestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
parse_attachments(attachment_payload, {}) 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 # We can't parse entries that are not base64 but specified as
# though they are # though they are
attachment_payload = { attachment_payload = {

View File

@@ -178,7 +178,6 @@ class HTTPAttachment(A_MGR['http']):
'Could not prepare {} attachment in {}'.format( 'Could not prepare {} attachment in {}'.format(
filename, settings.APPRISE_ATTACH_DIR)) filename, settings.APPRISE_ATTACH_DIR))
# Prepare our item # Prepare our item
super().__init__(name=filename, **kwargs) super().__init__(name=filename, **kwargs)
@@ -272,6 +271,14 @@ def parse_attachments(attachment_payload, files_request):
# Prepare our Attachment # Prepare our Attachment
# #
if isinstance(entry, str): 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): if not re.match(r'^https?://.+', entry[:10], re.I):
# We failed to retrieve the product # We failed to retrieve the product
raise ValueError( raise ValueError(