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

[bug] Emails with capital letters invalid when config has `gmail: false` #5

Closed mattwelke closed 1 year ago

mattwelke commented 1 year ago

Describe the bug

Node.js version: Node.js 18

OS version: Ubuntu 22.04

Description:

When changing the Gmail mode from its default true to false, the regex produced considers email addresses with capital letters invalid. I think email addresses that have capital letters are valid because apparently modern email servers ignore case.

Can you clarify? Is this a bug or intended behavior? If intended, why?

Actual behavior

Regex produced with gmail: false in config considers emails invalid if they have a capital letter.

Expected behavior

Regex produced with gmail: false in config does not consider emails invalid if they have a capital letter.

Code to reproduce

Use this code to get the regex:

const emailRegexSafe = require('email-regex-safe');
const regexString = emailRegexSafe({
    exact: true,
    returnString: true,
    gmail: false,
});

(can console log it etc)

Or, check out the latest commit in the branch in the repo for an open source lib I maintain at https://github.com/schema-inspector/schema-inspector/pull/143. One of our unit tests is failing with candidate "nikitaJS@pantera.com" when I change to the new regex.

Checklist

titanism commented 1 year ago

This would be a bug - PR is welcome to fix. Typically though we would toLowerCase() before running against this.

mattwelke commented 1 year ago

@titanism Would lowercasing input before validating using this be a good workaround? In the library I maintain, we could do this as a workaround, if I struggle to get a PR in here.

titanism commented 1 year ago

Yes that's what we do