spamscanner / email-regex-safe

Regular expression matching for email addresses. Maintained, configurable, more accurate, and browser-friendly alternative to email-regex. Works in Node v14+ and browsers. Made for @spamscanner and @forwardemail.
https://forwardemail.net/docs/email-address-regex-javascript-node-js
MIT License
18 stars 8 forks source link

[fix] `a@abc.de` does not match #8

Open analog-nico opened 9 months ago

analog-nico commented 9 months ago

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('a@abc.de') returns false. Note that the local part has only 1 character. If I add a second character it works fine.

Actual behavior

emailRegex.test('a@abc.de') returns false

Expected behavior

emailRegex.test('a@abc.de') 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('a@abc.de')

Run this code on RunKit

Checklist

analog-nico commented 9 months ago

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.