Make WordPress Core

Ticket #45714: 45714.patch

File 45714.patch, 2.3 KB (added by chrisl27, 6 years ago)

Patch

  • src/wp-admin/includes/user.php

    diff --git src/wp-admin/includes/user.php src/wp-admin/includes/user.php
    index 4e454c6a7f..bf22256c5b 100644
    function edit_user( $user_id = 0 ) { 
    7777        }
    7878
    7979        if ( isset( $_POST['email'] ) ) {
    80                 $user->user_email = sanitize_text_field( wp_unslash( $_POST['email'] ) );
     80                $user->user_email = sanitize_email( wp_unslash( $_POST['email'] ) );
    8181        }
    8282        if ( isset( $_POST['url'] ) ) {
    8383                if ( empty( $_POST['url'] ) || $_POST['url'] == 'http://' ) {
  • tests/phpunit/tests/user.php

    diff --git tests/phpunit/tests/user.php tests/phpunit/tests/user.php
    index 4f9fa2ba1b..c7c436db34 100644
    class Tests_User extends WP_UnitTestCase { 
    14211421                $this->assertEquals( 'nickname_updated2', $user->nickname );
    14221422        }
    14231423
     1424        /**
     1425          * Checks that edit_user() correctly sanitizes the supplied email address
     1426          *
     1427          * @ticket 45714
     1428          */
     1429        function test_edit_user_sanitize_password() {
     1430                $_POST = $_GET = $_REQUEST = array();
     1431
     1432                $user = $this->factory()->user->create_and_get( array(
     1433                        'email' => 'eusp1@example.com',
     1434                ) );
     1435
     1436                $_POST['nickname']   = 'eusp1';
     1437                $_POST['user_login'] = $user->user_login;
     1438
     1439                // Success cases
     1440                foreach ( array(
     1441                        'eusp2@example.com'       => 'eusp2@example.com',
     1442                        'eusp3%4@example.com'     => 'eusp3%4@example.com',
     1443                        'eusp4@example.com!'      => 'eusp4@example.com',
     1444                        '  eusp6@example.com%aa ' => 'eusp6@example.comaa',
     1445                        'eu\'sp@example.com'      => 'eu\'sp@example.com',
     1446                ) as $em_pre => $em_post ) {
     1447                        $_POST['email'] = $em_pre;
     1448
     1449                        $user_id = edit_user( $user->ID );
     1450
     1451                        $this->assertInternalType( 'int', $user_id );
     1452
     1453                        $user = get_user_by( 'ID', $user_id );
     1454
     1455                        $this->assertInstanceOf( 'WP_User', $user );
     1456                        $this->assertEquals( $em_post, $user->user_email );
     1457                }
     1458
     1459                // Failure cases (resulting in an invalid email address)
     1460                foreach ( array(
     1461                        ''      => '',
     1462                        'eusp5' => 'eusp5',
     1463                ) as $em_pre => $em_post ) {
     1464                        $_POST['email'] = $em_pre;
     1465                        $user_id = edit_user( $user->ID );
     1466
     1467                        /** @type WP_Error $user_id */
     1468                        $this->assertInstanceOf( 'WP_Error', $user_id );
     1469                        $this->assertEquals('empty_email', $user_id->get_error_code());
     1470                }
     1471        }
     1472
    14241473        /**
    14251474         * Check passwords action for test_edit_user_blank_pw().
    14261475         */