Skip to content
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

Fix isEmail does not support domain IP address #38758

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

Conversation

ediamin
Copy link
Contributor

@ediamin ediamin commented Feb 12, 2022

Description

Fixes #38105.

Currently the isEmail in @wordpress/url returns false is we use email with domain IP address like ace@204.32.222.14. This PR fixes this issue and add support for the emails using domain IP.

Testing Instructions

import { isEmail } from '@wordpress/url';

console.log( isEmail( 'ace@204.32.222.14' ) ); // Should be return true after applying the fix.

Types of changes

  1. Fixes the regular expression that validates the email string.
  2. Add an email with domain ip in the test case.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).
  • I've updated related schemas if appropriate.
@ediamin ediamin changed the title Fix isEmail does not support domain ip Feb 12, 2022
@Mamaduka Mamaduka added [Package] Url /packages/url [Type] Bug An existing feature does not function as intended labels Feb 12, 2022
@@ -1,4 +1,4 @@
const EMAIL_REGEXP = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
const EMAIL_REGEXP = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z0-9]{2,63}$/i;
Copy link
Member

Choose a reason for hiding this comment

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

This will fail for IPs with a single number at the end ace@1.1.1.1 and succeed for incorrect IPs, like one with a number higher than 255 (ace@900.1.1.1), with 4 numbers (ace@1111.1.1.1), or with less or more than 4 sets of numbers (ace@1.1.1, ace@1.1.1.1.1).

Why don't we add a proper IP regex, like ^((1?[1-9]?\d|25[0-5]|2[0-4]\d)\.){3}(1?[1-9]?\d|25[0-5]|2[0-4]\d)$? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Url /packages/url [Type] Bug An existing feature does not function as intended
3 participants