Make WordPress Core

Changeset 46473 for branches/5.2


Ignore:
Timestamp:
10/14/2019 11:03:34 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Formatting: In wp_validate_redirect(), normalize the path when validating the location for relative URLs, to account for Windows paths.

Props peterwilsoncc, rconde, jmmathc, mat-lipe, Sixes, justinahinon, cmagrin, daxelrod, SergeyBiryukov.
Merges [46472] to the 5.2 branch.
Fixes #47980.

Location:
branches/5.2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2

  • branches/5.2/src/wp-includes/pluggable.php

    r45972 r46473  
    14011401                        if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
    14021402                                $path = dirname( parse_url( 'http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH ) . '?' );
     1403                                $path = wp_normalize_path( $path );
    14031404                        }
    14041405                        $location = '/' . ltrim( $path . '/', '/' ) . $location;
  • branches/5.2/tests/phpunit/tests/formatting/redirect.php

    r44584 r46473  
    134134                );
    135135        }
     136
     137        /**
     138         * @ticket 47980
     139         * @dataProvider relative_url_provider
     140         */
     141        function test_wp_validate_redirect_relative_url( $current_uri, $url, $expected ) {
     142                // Backup the global.
     143                $unset = false;
     144                if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
     145                        $unset = true;
     146                } else {
     147                        $backup_request_uri = $_SERVER['REQUEST_URI'];
     148                }
     149
     150                // Set the global to current URI.
     151                $_SERVER['REQUEST_URI'] = $current_uri;
     152
     153                $this->assertEquals( $expected, wp_validate_redirect( $url, false ) );
     154
     155                // Delete or reset the global as required.
     156                if ( $unset ) {
     157                        unset( $_SERVER['REQUEST_URI'] );
     158                } else {
     159                        $_SERVER['REQUEST_URI'] = $backup_request_uri;
     160                }
     161        }
     162
     163        /**
     164         * Data provider for test_wp_validate_redirect_relative_url.
     165         *
     166         * @return array[] {
     167         *      string Current URI (i.e. path and query string only).
     168         *      string Redirect requested.
     169         *      string Expected destination.
     170         * }
     171         */
     172        function relative_url_provider() {
     173                return array(
     174                        array(
     175                                '/',
     176                                'wp-login.php?loggedout=true',
     177                                '/wp-login.php?loggedout=true',
     178                        ),
     179                        array(
     180                                '/src/',
     181                                'wp-login.php?loggedout=true',
     182                                '/src/wp-login.php?loggedout=true',
     183                        ),
     184                        array(
     185                                '/wp-admin/settings.php?page=my-plugin',
     186                                './settings.php?page=my-plugin',
     187                                '/wp-admin/./settings.php?page=my-plugin',
     188                        ),
     189                        array(
     190                                '/wp-admin/settings.php?page=my-plugin',
     191                                '/wp-login.php',
     192                                '/wp-login.php',
     193                        ),
     194                        array(
     195                                '/wp-admin/settings.php?page=my-plugin',
     196                                '../wp-admin/admin.php?page=my-plugin',
     197                                '/wp-admin/../wp-admin/admin.php?page=my-plugin',
     198                        ),
     199                        array(
     200                                '/2019/10/13/my-post',
     201                                '../../',
     202                                '/2019/10/13/../../',
     203                        ),
     204                        array(
     205                                '/2019/10/13/my-post',
     206                                '/',
     207                                '/',
     208                        ),
     209                );
     210        }
    136211}
Note: See TracChangeset for help on using the changeset viewer.