Make WordPress Core

Ticket #31992: 31992-icann.patch

File 31992-icann.patch, 3.5 KB (added by agulbra, 17 months ago)

Patch to add support for unicode email addresses in is_email, but making no other changes and resolving no other limitations

  • src/wp-includes/formatting.php

    commit 9740f5cb43af8ec4828d23d32cb4adfe5da18c4d
    Author: Arnt Gulbrandsen <arnt@gulbrandsen.priv.no>
    Date:   Fri Apr 28 12:03:03 2023 +0200
    
        General: Add support for unicode email addresses in is_email
        
        This adds support for the unicode address extensions in RFC 6532, adds
        unit tests for that, extends the documentation to explain the relationship
        between this code and the various specifications, and finally adds unit
        tests to ensure that the documentation's description of the code remains
        correct.
        
        Fixes #31992.
    
    diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
    index 8240adcc82..ec3aba1ef0 100644
    a b function convert_smilies( $text ) { 
    34893489/**
    34903490 * Verifies that an email is valid.
    34913491 *
    3492  * Does not grok i18n domains. Not RFC compliant.
     3492 * The mostly matches what people think is the format of email
     3493 * addresses, and is close to all three current specifications.
     3494 *
     3495 * Email address syntax is specified in RFC 5322 for ASCII-only email
     3496 * and in RFC 6532 for unicode email (both unicode domains and
     3497 * localparts). In addition, the HTML WHATWG specification contains a
     3498 * third syntax which is used for HTML form input (except that major
     3499 * browsers deviate a little from the WHATWG specification).
     3500 *
     3501 * This function matches the WHATWG and RFC 6532 specifications fairly
     3502 * well, although there are some differences.  " "@example.com (quote
     3503 * space quote at ...) is allowed by the RFCs and rejected by this
     3504 * code, while ..@example.com is allowed by this code and prohibited
     3505 * by the RFCs. info@grå.org is allowed by this code and major
     3506 * browsers, but prohibited by WHATWG's regex (as of April 2023).
    34933507 *
    34943508 * @since 0.71
    34953509 *
    function is_email( $email, $deprecated = false ) { 
    35313545
    35323546        // LOCAL PART
    35333547        // Test for invalid characters.
    3534         if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
     3548        if ( ! ( preg_match( '/^[a-zA-Z0-9\x80-\xff!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) &&
     3549                 preg_match( '/^\X+$/', $local ) ) ) {
    35353550                /** This filter is documented in wp-includes/formatting.php */
    35363551                return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
    35373552        }
    function is_email( $email, $deprecated = false ) { 
    35673582                }
    35683583
    35693584                // Test for invalid characters.
    3570                 if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) {
     3585                if ( ! ( preg_match( '/^[a-z0-9\x80-\xff-]+$/i', $sub ) &&
     3586                         preg_match( '/^\X+$/', $sub ) ) ) {
    35713587                        /** This filter is documented in wp-includes/formatting.php */
    35723588                        return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
    35733589                }
  • tests/phpunit/tests/formatting/isEmail.php

    diff --git a/tests/phpunit/tests/formatting/isEmail.php b/tests/phpunit/tests/formatting/isEmail.php
    index c3f0a7c45b..cbdc1067cd 100644
    a b class Tests_Formatting_IsEmail extends WP_UnitTestCase { 
    1414                        'kevin@many.subdomains.make.a.happy.man.edu',
    1515                        'a@b.co',
    1616                        'bill+ted@example.com',
     17                        'info@grå.org',
     18                        'grå@grå.org',
     19                        "gr\u{0061}\u{030a}blå@grå.org",
     20                        '..@example.com',
    1721                );
    1822                foreach ( $data as $datum ) {
    1923                        $this->assertSame( $datum, is_email( $datum ), $datum );
    class Tests_Formatting_IsEmail extends WP_UnitTestCase { 
    2832                        'com.exampleNOSPAMbob',
    2933                        'bob@your mom',
    3034                        'a@b.c',
     35                        '" "@b.c',
    3136                );
    3237                foreach ( $data as $datum ) {
    3338                        $this->assertFalse( is_email( $datum ), $datum );