Make WordPress Core

Ticket #47980: 47980.diff

File 47980.diff, 2.7 KB (added by peterwilsoncc, 5 years ago)
  • src/wp-includes/pluggable.php

    diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php
    index 468e065586..206761aaef 100644
    a b if ( ! function_exists( 'wp_validate_redirect' ) ) : 
    14181418                        $path = '';
    14191419                        if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
    14201420                                $path = dirname( parse_url( 'http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH ) . '?' );
     1421                                $path = wp_normalize_path( $path );
    14211422                        }
    14221423                        $location = '/' . ltrim( $path . '/', '/' ) . $location;
    14231424                }
  • tests/phpunit/tests/formatting/redirect.php

    diff --git a/tests/phpunit/tests/formatting/redirect.php b/tests/phpunit/tests/formatting/redirect.php
    index 493dae4a1c..ea8ac0fd39 100644
    a b class Tests_Formatting_Redirect extends WP_UnitTestCase { 
    5858                $this->assertEquals( false, wp_validate_redirect( $url, false ) );
    5959        }
    6060
     61        /**
     62         * @ticket 47980
     63         * @dataProvider relative_url_provider
     64         */
     65        function test_wp_validate_redirect_relative_url( $current_uri, $url, $expected ) {
     66                // Backup the global.
     67                $unset = false;
     68                if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
     69                        $unset = true;
     70                } else {
     71                        $backup_request_uri = $_SERVER['REQUEST_URI'];
     72                }
     73
     74                // Set the global to current URI.
     75                $_SERVER['REQUEST_URI'] = $current_uri;
     76
     77                $this->assertEquals( $expected, wp_validate_redirect( $url, false ) );
     78
     79                // Delete or reset the global as required.
     80                if ( $unset ) {
     81                        unset( $_SERVER['REQUEST_URI'] );
     82                } else {
     83                        $_SERVER['REQUEST_URI'] = $backup_request_uri;
     84                }
     85        }
     86
    6187        function valid_url_provider() {
    6288                return array(
    6389                        array( 'http://example.com', 'http://example.com' ),
    class Tests_Formatting_Redirect extends WP_UnitTestCase { 
    141167                        array( 'http://user.pass@#example.com/' ),
    142168                );
    143169        }
     170
     171        /**
     172         * Data provider for test_wp_validate_redirect_relative_url.
     173         *
     174         * @return array[] {
     175         *      string Current URI (ie path and query string only).
     176         *      string Redirect requested.
     177         *      string Expected destination.
     178         * }
     179         */
     180        function relative_url_provider() {
     181                return array(
     182                        array(
     183                                '/wp-admin/settings.php?page=my-plugin',
     184                                './settings.php?page=my-plugin',
     185                                '/wp-admin/./settings.php?page=my-plugin',
     186                        ),
     187                        array(
     188                                '/wp-admin/settings.php?page=my-plugin',
     189                                '/wp-login.php',
     190                                '/wp-login.php',
     191                        ),
     192                        array(
     193                                '/wp-admin/settings.php?page=my-plugin',
     194                                '../wp-admin/admin.php?page=my-plugin',
     195                                '/wp-admin/../wp-admin/admin.php?page=my-plugin',
     196                        ),
     197                        array(
     198                                '/2019/10/13/my-post',
     199                                '../../',
     200                                '/2019/10/13/../../',
     201                        ),
     202                        array(
     203                                '/2019/10/13/my-post',
     204                                '/',
     205                                '/',
     206                        ),
     207                );
     208        }
    144209}