LibrePhotos/librephotos

Replace regex-based email validation

Open

#695 opened on Dec 11, 2022

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Python (266 forks)batch import
difficulty: easyenhancementfrontendgood first issuesize: XS

Repository metrics

Stars
 (6,222 stars)
PR merge metrics
 (Avg merge 5d 23h) (29 merged PRs in 30d)

Description

Describe the enhancement you'd like Replace regex-based email validation with something more robust & easier to read

Describe why this will benefit the LibrePhotos It appears the general consensus on email validation is that regex is a suboptimal solution. I'm no expert here, but some compelling arguments I've seen are:

  • it's difficult to read and maintain
  • if it's not overly difficult to read, it's likely violating RFC 5322

The current solution for email validation has proven problematic at least twice, including #689, #637; perhaps more.

Additional context This SO post shows exactly how complicated a "proper" regex-based email validator would be, and it's essentially impossible to read:

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

Contributor guide