You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2022/01/28 15:37:16 UTC

[incubator-ponymail-foal] branch master updated: assert is not suitable for external value checks

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new 8094261  assert is not suitable for external value checks
8094261 is described below

commit 8094261b600a901156b4652e2b3f2865b5917044
Author: Sebb <se...@apache.org>
AuthorDate: Fri Jan 28 15:37:07 2022 +0000

    assert is not suitable for external value checks
    
    See #87
---
 server/endpoints/mgmt.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/server/endpoints/mgmt.py b/server/endpoints/mgmt.py
index 8811395..51d4a0d 100644
--- a/server/endpoints/mgmt.py
+++ b/server/endpoints/mgmt.py
@@ -132,6 +132,7 @@ async def process(
     # Editing an email in place
     elif action == "edit":
         new_from = indata.get("from")
+        print(new_from)
         new_subject = indata.get("subject")
         new_list = indata.get("list", "")
         private = indata.get("private", "yes") == "yes" # Assume private unless notified otherwise
@@ -139,11 +140,16 @@ async def process(
         attach_edit = indata.get("attachments", None)
 
         # Check for consistency so we don't pollute the database
-        assert isinstance(doc, str) and doc, "Document ID is missing or invalid"
-        assert isinstance(new_from, str), "Author field must be a text string!"
-        assert isinstance(new_subject, str), "Subject field must be a text string!"
-        assert isinstance(new_list, str), "List ID field must be a text string!"
-        assert isinstance(new_body, str), "Email body must be a text string!"
+        if not isinstance(doc, str):
+            raise ValueError("Document ID is missing or invalid")
+        if not isinstance(new_from, str):
+            raise ValueError("Author field must be a text string!")
+        if not isinstance(new_subject, str):
+            raise ValueError("Subject field must be a text string!")
+        if not isinstance(new_list, str):
+            raise ValueError("List ID field must be a text string!")
+        if not isinstance(new_body, str):
+            raise ValueError("Email body must be a text string!")
 
         # Convert List-ID after verification
         lid = "<" + new_list.strip("<>").replace("@", ".") + ">"  # foo@bar.baz -> <foo.bar.baz>