Make WordPress Core

Ticket #38744: 38744-fixes.3.diff.patch

File 38744-fixes.3.diff.patch, 3.4 KB (added by nsubugak, 6 years ago)

Added Unit Test for this Patch.

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

     
    4141        }
    4242
    4343        if ( ! $update && isset( $_POST['user_login'] ) ) {
    44                 $user->user_login = sanitize_user( $_POST['user_login'], true );
     44                $user->user_login = sanitize_user( wp_unslash( $_POST['user_login'] ), true );
    4545        }
    4646
    4747        $pass1 = $pass2 = '';
  • src/wp-includes/user.php

     
    3535                $credentials = array(); // Back-compat for plugins passing an empty string.
    3636
    3737                if ( ! empty( $_POST['log'] ) ) {
    38                         $credentials['user_login'] = $_POST['log'];
     38                        $credentials['user_login'] = wp_unslash( $_POST['log'] );
    3939                }
    4040                if ( ! empty( $_POST['pwd'] ) ) {
    4141                        $credentials['user_password'] = $_POST['pwd'];
  • src/wp-login.php

     
    805805
    806806                if ( $http_post ) {
    807807                        if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
    808                                 $user_login = $_POST['user_login'];
     808                                $user_login = wp_unslash( $_POST['user_login'] );
    809809                        }
    810810
    811811                        if ( isset( $_POST['user_email'] ) && is_string( $_POST['user_email'] ) ) {
     
    913913
    914914                // If the user wants SSL but the session is not SSL, force a secure cookie.
    915915                if ( ! empty( $_POST['log'] ) && ! force_ssl_admin() ) {
    916                         $user_name = sanitize_user( $_POST['log'] );
     916                        $user_name = sanitize_user( wp_unslash( $_POST['log'] ));
    917917                        $user      = get_user_by( 'login', $user_name );
    918918
    919919                        if ( ! $user && strpos( $user_name, '@' ) ) {
  • tests/phpunit/tests/user.php

     
    3434                        )
    3535                );
    3636
     37                self::$user_ids[]  = $factory->user->create(
     38                        array(
     39                                'user_login'    => "testemailaddress'@test.com",
     40                                'user_nicename' => 'user_email_with_apostrophe',
     41                                'user_pass'     => 'password',
     42                                'first_name'    => 'John',
     43                                'last_name'     => 'Doe',
     44                                'display_name'  => 'John Doe',
     45                                'user_email'    => "testemailaddress'@test.com",
     46                                'user_url'      => 'http://tacos.com',
     47                                'role'          => 'contributor',
     48                                'nickname'      => 'Johnny',
     49                                'description'   => 'I am a WordPress user that cares about privacy.',
     50                        )
     51                );
     52
    3753                self::$user_ids[] = self::$author_id = $factory->user->create(
    3854                        array(
    3955                                'user_login' => 'author_login',
     
    6076                $this->author = clone self::$_author;
    6177        }
    6278
     79        public function test_that_you_can_login_with_an_email_that_has_apostrophe(){
     80       
     81                //create the user with an email that has an apostrophe (see test setup)
     82               
     83                //login as the user
     84                $credentials = [
     85                        'user_login' => "testemailaddress'@test.com",
     86                        'user_password' => 'password'
     87                ];
     88               
     89                //attempt to login
     90                $user = wp_signon($credentials);
     91       
     92                //assert that login was successfull
     93                //if the login fails, an instance of WP_Error is returned rather than User object
     94                $this->assertNotWPError($user);
     95        }
     96
    6397        function test_get_users_of_blog() {
    6498                // add one of each user role
    6599                $nusers = array(