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' ) ) : |
| 1418 | 1418 | $path = ''; |
| 1419 | 1419 | if ( ! empty( $_SERVER['REQUEST_URI'] ) ) { |
| 1420 | 1420 | $path = dirname( parse_url( 'http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH ) . '?' ); |
| | 1421 | $path = wp_normalize_path( $path ); |
| 1421 | 1422 | } |
| 1422 | 1423 | $location = '/' . ltrim( $path . '/', '/' ) . $location; |
| 1423 | 1424 | } |
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 { |
| 58 | 58 | $this->assertEquals( false, wp_validate_redirect( $url, false ) ); |
| 59 | 59 | } |
| 60 | 60 | |
| | 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 | |
| 61 | 87 | function valid_url_provider() { |
| 62 | 88 | return array( |
| 63 | 89 | array( 'http://example.com', 'http://example.com' ), |
| … |
… |
class Tests_Formatting_Redirect extends WP_UnitTestCase { |
| 141 | 167 | array( 'http://user.pass@#example.com/' ), |
| 142 | 168 | ); |
| 143 | 169 | } |
| | 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 | } |
| 144 | 209 | } |