Skip to content

Commit bbe1466

Browse files
authored
Fix bug in normalize_and_hash_email_address function (#752)
1 parent 6b13083 commit bbe1466

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

examples/remarketing/upload_enhanced_conversions_for_leads.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,19 @@ def normalize_and_hash_email_address(email_address):
196196
Returns:
197197
A normalized (lowercase, removed whitespace) and SHA-265 hashed string.
198198
"""
199-
normalized_email = email_address.lower()
199+
normalized_email = email_address.strip().lower()
200200
email_parts = normalized_email.split("@")
201-
# Checks whether the domain of the email address is either "gmail.com"
202-
# or "googlemail.com". If this regex does not match then this statement
203-
# will evaluate to None.
204-
is_gmail = re.match(r"^(gmail|googlemail)\.com$", email_parts[1])
205-
206-
# Check that there are at least two segments and the second segment
207-
# matches the above regex expression validating the email domain name.
208-
if len(email_parts) > 1 and is_gmail:
209-
# Removes any '.' characters from the portion of the email address
210-
# before the domain if the domain is gmail.com or googlemail.com.
211-
email_parts[0] = email_parts[0].replace(".", "")
212-
normalized_email = "@".join(email_parts)
201+
202+
# Check that there are at least two segments
203+
if len(email_parts) > 1:
204+
# Checks whether the domain of the email address is either "gmail.com"
205+
# or "googlemail.com". If this regex does not match then this statement
206+
# will evaluate to None.
207+
if re.match(r"^(gmail|googlemail)\.com$", email_parts[1]):
208+
# Removes any '.' characters from the portion of the email address
209+
# before the domain if the domain is gmail.com or googlemail.com.
210+
email_parts[0] = email_parts[0].replace(".", "")
211+
normalized_email = "@".join(email_parts)
213212

214213
return normalize_and_hash(normalized_email)
215214

examples/remarketing/upload_enhanced_conversions_for_web.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,19 @@ def normalize_and_hash_email_address(email_address):
228228
Returns:
229229
A normalized (lowercase, removed whitespace) and SHA-265 hashed string.
230230
"""
231-
normalized_email = email_address.lower()
231+
normalized_email = email_address.strip().lower()
232232
email_parts = normalized_email.split("@")
233-
# Checks whether the domain of the email address is either "gmail.com"
234-
# or "googlemail.com". If this regex does not match then this statement
235-
# will evaluate to None.
236-
is_gmail = re.match(r"^(gmail|googlemail)\.com$", email_parts[1])
237-
238-
# Check that there are at least two segments and the second segment
239-
# matches the above regex expression validating the email domain name.
240-
if len(email_parts) > 1 and is_gmail:
241-
# Removes any '.' characters from the portion of the email address
242-
# before the domain if the domain is gmail.com or googlemail.com.
243-
email_parts[0] = email_parts[0].replace(".", "")
244-
normalized_email = "@".join(email_parts)
233+
234+
# Check that there are at least two segments
235+
if len(email_parts) > 1:
236+
# Checks whether the domain of the email address is either "gmail.com"
237+
# or "googlemail.com". If this regex does not match then this statement
238+
# will evaluate to None.
239+
if re.match(r"^(gmail|googlemail)\.com$", email_parts[1]):
240+
# Removes any '.' characters from the portion of the email address
241+
# before the domain if the domain is gmail.com or googlemail.com.
242+
email_parts[0] = email_parts[0].replace(".", "")
243+
normalized_email = "@".join(email_parts)
245244

246245
return normalize_and_hash(normalized_email)
247246

0 commit comments

Comments
 (0)