You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2020/04/15 13:58:14 UTC

[incubator-superset] branch master updated: Make email parsing more robust (#9523)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3574a3a  Make email parsing more robust (#9523)
3574a3a is described below

commit 3574a3a4fb089308918b70c54598b4fdd6a818b4
Author: Bogdan <b....@gmail.com>
AuthorDate: Wed Apr 15 06:58:03 2020 -0700

    Make email parsing more robust (#9523)
    
    * Make email parsing more robust
    
    * Address comment
    
    Co-authored-by: bogdan kyryliuk <bo...@dropbox.com>
---
 superset/utils/core.py | 10 ++--------
 tests/utils_tests.py   | 11 +++++++++++
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/superset/utils/core.py b/superset/utils/core.py
index ca49989..15d8542 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -23,6 +23,7 @@ import hashlib
 import json
 import logging
 import os
+import re
 import signal
 import smtplib
 import tempfile
@@ -783,14 +784,7 @@ def send_MIME_email(e_from, e_to, mime_msg, config, dryrun=False):
 def get_email_address_list(address_string: str) -> List[str]:
     address_string_list: List[str] = []
     if isinstance(address_string, str):
-        if "," in address_string:
-            address_string_list = address_string.split(",")
-        elif "\n" in address_string:
-            address_string_list = address_string.split("\n")
-        elif ";" in address_string:
-            address_string_list = address_string.split(";")
-        else:
-            address_string_list = [address_string]
+        address_string_list = re.split(",|\s|;", address_string)
     return [x.strip() for x in address_string_list if x.strip()]
 
 
diff --git a/tests/utils_tests.py b/tests/utils_tests.py
index 9a5d8f6..70b77af 100644
--- a/tests/utils_tests.py
+++ b/tests/utils_tests.py
@@ -40,6 +40,7 @@ from superset.utils.core import (
     datetime_f,
     format_timedelta,
     get_iterable,
+    get_email_address_list,
     get_or_create_db,
     get_since_until,
     get_stacktrace,
@@ -1238,3 +1239,13 @@ class UtilsTestCase(SupersetTestCase):
         expected_filename = hashlib.md5(ssl_certificate.encode("utf-8")).hexdigest()
         self.assertIn(expected_filename, path)
         self.assertTrue(os.path.exists(path))
+
+    def test_get_email_address_list(self):
+        self.assertEqual(get_email_address_list("a@a"), ["a@a"])
+        self.assertEqual(get_email_address_list(" a@a "), ["a@a"])
+        self.assertEqual(get_email_address_list("a@a\n"), ["a@a"])
+        self.assertEqual(get_email_address_list(",a@a;"), ["a@a"])
+        self.assertEqual(
+            get_email_address_list(",a@a; b@b c@c a-c@c; d@d, f@f"),
+            ["a@a", "b@b", "c@c", "a-c@c", "d@d", "f@f"],
+        )