email-regex-safe icon indicating copy to clipboard operation
email-regex-safe copied to clipboard

[fix] `[email protected]` does not match

Open analog-nico opened this issue 1 year ago • 1 comments

Describe the bug

I ran it on RunKit and on my local system:

Node.js version: 18.11 and 20.9

OS version: RunKit’s OS and Mac OS X

Description: emailRegex.test('[email protected]') returns false. Note that the local part has only 1 character. If I add a second character it works fine.

Actual behavior

emailRegex.test('[email protected]') returns false

Expected behavior

emailRegex.test('[email protected]') returns true

Code to reproduce

require("re2/package.json"); // re2 is a peer dependency. 
var emailRegexSafe = require("email-regex-safe")

let emailRegex = emailRegexSafe({ exact: true, gmail: false })

emailRegex.test('[email protected]')

Run this code on RunKit

Checklist

  • [x] I have searched through GitHub issues for similar issues.
  • [x] I have completely read through the README and documentation.
  • [x] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

analog-nico avatar Jan 22 '24 14:01 analog-nico

I looked into the generated regex:

(?:[^\W_](?:[a-z\d!#\$%&'\.\*\+\-\/=\?\^_{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)@...)`

The (?:[^\W_] part seems to be the culprit. Unfortunately, I don’t understand why it is not an issue if the local part of the email address has more than 1 character.

analog-nico avatar Jan 22 '24 14:01 analog-nico