Make WordPress Core

Ticket #42957: 42957.diff

File 42957.diff, 3.4 KB (added by daveagp, 4 years ago)

Diff generated from github pull request

  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 56d5fd9f43..c4fa380fc0 100644
    a b function wp_get_direct_php_update_url() { 
    75597559        return $direct_update_url;
    75607560}
    75617561
     7562/**
     7563 * Encode this url, like rawurlencode. If it ends in a period, replace that with %2E.
     7564 * This is done because gmail doesn't interpret it right otherwise.
     7565 * See https://core.trac.wordpress.org/ticket/42957 for background.
     7566 *
     7567 * @param string  $url Any url.
     7568 * @return string Encoded url.
     7569 */
     7570function wp_half_baked_url_encode( $url ) {
     7571        return preg_replace( '/\.$/', '%2E', rawurlencode( $url ) );
     7572}
     7573
    75627574/**
    75637575 * Display a button directly linking to a PHP update process.
    75647576 *
  • src/wp-includes/pluggable.php

    diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php
    index c53a723fc4..2a148d2d82 100644
    a b if ( ! function_exists( 'wp_new_user_notification' ) ) : 
    20822082                /* translators: %s: User login. */
    20832083                $message  = sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
    20842084                $message .= __( 'To set your password, visit the following address:' ) . "\r\n\r\n";
    2085                 $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), 'login' ) . "\r\n\r\n";
     2085                $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . wp_half_baked_url_encode( $user->user_login ), 'login' ) . "\r\n\r\n";
    20862086
    20872087                $message .= wp_login_url() . "\r\n";
    20882088
  • src/wp-includes/user.php

    diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
    index c4c44a0c69..3a9c04ca54 100644
    a b function retrieve_password( $user_login = null ) { 
    27712771        $message .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n\r\n";
    27722772        $message .= __( 'If this was a mistake, ignore this email and nothing will happen.' ) . "\r\n\r\n";
    27732773        $message .= __( 'To reset your password, visit the following address:' ) . "\r\n\r\n";
    2774         $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "\r\n\r\n";
     2774        $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . wp_half_baked_url_encode( $user_login ), 'login' ) . "\r\n\r\n";
    27752775
    27762776        if ( ! is_user_logged_in() ) {
    27772777                $requester_ip = $_SERVER['REMOTE_ADDR'];
  • new file tests/phpunit/tests/functions/wpHalfBakedUrlEncode.php

    diff --git a/tests/phpunit/tests/functions/wpHalfBakedUrlEncode.php b/tests/phpunit/tests/functions/wpHalfBakedUrlEncode.php
    new file mode 100644
    index 0000000000..cb9880a0ef
    - +  
     1<?php
     2
     3/**
     4 * Tests for wp_half_baked_url_encode()
     5 *
     6 * @ticket 42957
     7 *
     8 * @group functions.php
     9 * @covers ::wp_half_baked_url_encode
     10 */
     11class Tests_Functions_WpHalfBakedUrlEncode extends WP_UnitTestCase {
     12
     13        public function _data_wp_half_baked_url_encode() {
     14                return array(
     15                        array( '', '' ),
     16                        array( '.', '%2E' ),
     17                        array( '..', '.%2E' ),
     18                        array( '...', '..%2E' ),
     19                        array( 'Ending period.', 'Ending%20period%2E' ),
     20                        array( 'Middle.period', 'Middle.period' ),
     21                        array( 'No period', 'No%20period' ),
     22                        array( 'Two.periods.', 'Two.periods%2E' ),
     23                );
     24        }
     25
     26        /**
     27         * @dataProvider _data_wp_half_baked_url_encode
     28         *
     29         * @param $input_url
     30         * @param $expected
     31         */
     32        public function test_size_format( $input_url, $expected ) {
     33                $this->assertSame( $expected, wp_half_baked_url_encode( $input_url ) );
     34        }
     35}