Make WordPress Core


Ignore:
Timestamp:
06/10/2026 03:04:54 PM (2 months ago)
Author:
dmsnell
Message:

General: Add support for unicode email addresses in is_email and sanitize_email

This adds support for the unicode address extensions in RFC 6530-3 and refactors the code so there are fewer long regexes and less duplication between sanitize_email and is_email. A new class, WP_Email_Address, provides the shared parts.

Opting out of unicode support is easy, default-filters.php adds unicode support by adding filters, which can be removed.

sanitize_email no longer does major changes like removing an entire subdomain from someone's address, it only cleans up things like soft hyphens and whitespace — changes that happen when coping an email address from text.

Developed in: https://github.com/WordPress/wordpress-develop/pull/5237
Discussed in: https://core.trac.wordpress.org/ticket/31992

Props agulbra, akirk, benniledl, dmsnell, ironprogrammer, justlevine, mdawaffe, mukeshpanchal27, SirLouen, tusharbharti.
Fixes #31992.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/privacy/wpCreateUserRequest.php

    r55337 r62482  
    153153         */
    154154        public function test_sanitized_email() {
    155                 $actual = wp_create_user_request( 'some(email<withinvalid\characters@local.test', 'export_personal_data' );
    156 
    157                 $this->assertNotWPError( $actual );
    158 
    159                 $post = get_post( $actual );
    160 
    161                 $this->assertSame( 'export_personal_data', $post->post_name );
    162                 $this->assertSame( 'someemailwithinvalidcharacters@local.test', $post->post_title );
     155                // Address supplied in "Display Name <address>" format should be extracted and accepted.
     156                $actual = wp_create_user_request( 'Some User <sanitized@local.test>', 'export_personal_data' );
     157
     158                $this->assertNotWPError( $actual );
     159
     160                $post = get_post( $actual );
     161
     162                $this->assertSame( 'export_personal_data', $post->post_name );
     163                $this->assertSame( 'sanitized@local.test', $post->post_title );
    163164        }
    164165
Note: See TracChangeset for help on using the changeset viewer.