Make WordPress Core

Ticket #36827: 36827_guess_url_patch_and_test

File 36827_guess_url_patch_and_test, 1.5 KB (added by curdin, 10 years ago)

Regex pattern updated to correct wp-login dot issue and capture urls with query parameters. Added common urls identified earlier as unit tests. This is my first core patch, please let me know if I don't follow some convention ;)

Line 
1Index: src/wp-includes/functions.php
2===================================================================
3--- src/wp-includes/functions.php (revision 38147)
4+++ src/wp-includes/functions.php (working copy)
5@@ -4154,7 +4154,7 @@
6
7 // The request is for the admin
8 if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
9- $path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
10+ $path = preg_replace( '#/(wp-admin/?.*|wp-login\.php.*)#i', '', $_SERVER['REQUEST_URI'] );
11
12 // The request is for a file in ABSPATH
13 } elseif ( $script_filename_dir . '/' == $abspath_fix ) {
14Index: tests/phpunit/tests/includes/helpers.php
15===================================================================
16--- tests/phpunit/tests/includes/helpers.php (revision 38147)
17+++ tests/phpunit/tests/includes/helpers.php (working copy)
18@@ -212,4 +212,26 @@
19 public function test_die_handler_should_handle_wp_error() {
20 wp_die( new WP_Error( 'test', 'test' ) );
21 }
22+
23+
24+ function data_guessUrlTestCases() {
25+ return array(
26+ ['wp-admin'],
27+ ['wp-admin/'],
28+ ['wp-admin/?foo=bar'],
29+ ['wp-login.php'],
30+ ['wp-login.php?foo=bar']
31+ );
32+ }
33+
34+ /**
35+ * @dataProvider data_guessUrlTestCases
36+ * @ticket 36827
37+ */
38+ public function test_guessUrlShouldHandleEdgecases( $url ) {
39+ $siteurl = site_url();
40+ $this->go_to( site_url( $url ) );
41+ $this->assertEquals($siteurl, wp_guess_url());
42+ }
43+
44 }