diff --git a/google/ads/datamanager_util/format.py b/google/ads/datamanager_util/format.py index 197f2ca..865f2bb 100644 --- a/google/ads/datamanager_util/format.py +++ b/google/ads/datamanager_util/format.py @@ -90,6 +90,9 @@ def format_email_address(self, email: str) -> str: # "Create variations of your email address" at: # https://support.google.com/a/users/answer/9282734 + # Removes plus sign (+) and all characters that follow it. + user = user.split("+")[0] + # Removes all periods (.). user = re.sub("\\.", "", user) if len(user) == 0: diff --git a/tests/formatter_test.py b/tests/formatter_test.py index cbb48c9..afd3119 100644 --- a/tests/formatter_test.py +++ b/tests/formatter_test.py @@ -49,6 +49,24 @@ def test_format_email_address_valid_inputs(self): "Periods should be stripped from googlemail.com address", ) + self.assertEqual( + "cloudysanfrancisco@googlemail.com", + self.formatter.format_email_address("Cloudy.SanFrancisco+shopping@googlemail.com"), + "Plus sign and everything after should be stripped from googlemail.com address", + ) + + self.assertEqual( + "cloudysanfrancisco@gmail.com", + self.formatter.format_email_address("Cloudy.SanFrancisco+shopping@gmail.com"), + "Plus sign and everything after should be stripped from gmail.com address", + ) + + self.assertEqual( + "user.name+nyc@example.com", + self.formatter.format_email_address("user.name+NYC@Example.com"), + "Plus sign and everything after should not be stripped from non google emails", + ) + def test_format_email_address_invalid_inputs(self): with self.assertRaises(ValueError): self.formatter.format_email_address(None)