Skip to content

fix: normalize email addresses when retrieving from server #11055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SebastianKrupinski
Copy link
Contributor

resolves: client ticket - issue with email addresses being wrapped in single quotes

Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

🐘 did not test

// user1@example.com
// 'user1@example.com'
// ' user1@example.com'
return strtolower(trim(trim($address, "'")));
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned at #10980 (comment).

  • 'test@example.org is a valid email address.
  • The current normalizer incorrectly changes it to test@example.org

Example:

if (str_starts_with($address, "'") && str_ends_with($address, "'")) {
	$address = substr($address, 1, -1); // or trim($address, "'"); whatever you prefer
}
return strtolower(trim($address));

Given that we need the same logic in the repair job, I'd suggest moving the normalization to a small helper or utility service to make it reusable and more testable.

$select->expr()->like('email', $select->createNamedParameter('\'%\'', IQueryBuilder::PARAM_STR))
)
->setMaxResults(1000);
$recipients = $select->executeQuery()->fetchAll();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$recipients = $select->executeQuery()->fetchAll();
$result = $select->executeQuery();
$recipients = $result->fetchAll();
$result->closeCursor();

foreach ($recipients as $recipient) {
$id = $recipient['id'];
$email = $recipient['email'];
$email = trim(str_replace('\'', '', (string)$email));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$email = trim(str_replace('\'', '', (string)$email));
$email = trim(trim($email, "'"));

The best approach would be to reuse the logic from the address class. If we don't go with the helper/utility, we should still use trim to remove the first and last character (even if we can be very sure, due to the query, that we're only dealing with emails starting and ending with a ').

@st3iny st3iny mentioned this pull request May 26, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗️ In progress
Development

Successfully merging this pull request may close these issues.

3 participants