Make WordPress Core

Opened 11 months ago

Last modified 11 months 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: Mail Keywords: has-patch has-unit-tests
Focuses: Cc:


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 11 months ago.
25108.2.diff (1.3 KB) - added by DrewAPicture 11 months ago.
+ unit-test

Download all attachments as: .zip

Change History (7)

comment:1 rmccue11 months ago

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

comment:2 SergeyBiryukov11 months ago

  • Component changed from Validation to Mail

Related: #17491

DrewAPicture11 months ago

comment:3 DrewAPicture11 months ago

  • Keywords has-patch added

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

comment:4 nacin11 months 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.

DrewAPicture11 months ago

+ unit-test

comment:5 DrewAPicture11 months ago

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

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

Note: See TracTickets for help on using tickets.