Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions google/ads/datamanager_util/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions tests/formatter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ def test_format_email_address_valid_inputs(self):
"Periods should be stripped from googlemail.com address",
)

self.assertEqual(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use the same sample emails from the documentation.

"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)
Expand Down