WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 2 years ago

#25108 new defect (bug)

is_email() function validates email with domain that just has 1 character after dot

Reported by: hchouhan Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.6
Component: Formatting Keywords: has-patch has-unit-tests is-email
Focuses: Cc:

Description

is_email() function validates an email address that has domain name extension of just 1 character. I am not sure if there are any domains with just 1 character after.

To Test I used below code:

<?php if ( is_email( 'email@domain.c' ) ) {
      echo 'email address is valid.';
} ?>

Attachments (2)

25108.diff (816 bytes) - added by DrewAPicture 4 years ago.
25108.2.diff (1.3 KB) - added by DrewAPicture 4 years ago.
+ unit-test

Download all attachments as: .zip

Change History (8)

#1 @rmccue
4 years ago

This answer on Stack Overflow seems to indicate that in practice it's not valid, but it is valid in theory at least.

#2 @SergeyBiryukov
4 years ago

  • Component changed from Validation to Mail

Related: #17491

@DrewAPicture
4 years ago

#3 @DrewAPicture
4 years ago

  • Keywords has-patch added

25108.diff should work if we choose to "fix" this case.

#4 @nacin
4 years ago

  • Keywords needs-unit-tests added

In 25108.diff, we can probably wait until after the loop is finished, then check $sub (which will hold the final piece) or do end( $subs ).

Needs unit tests.

I think it's more than safe to exclude a one-letter TLD, yes.

@DrewAPicture
4 years ago

+ unit-test

#5 @DrewAPicture
4 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

25108.2.diff uses @nacin's suggested changes and adds (my first!) unit test.

#6 @miqrogroove
2 years ago

  • Component changed from Mail to Formatting
  • Keywords is-email added
Note: See TracTickets for help on using tickets.