Make WordPress Core

Changeset 32708


Ignore:
Timestamp:
06/08/2015 01:28:44 PM (11 years ago)
Author:
ocean90
Message:

Parse request: Quote regular expression characters in home path.

Adds unit tests.

props akirk.
fixes #30438.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp.php

    r32648 r32708  
    160160                        $self = $_SERVER['PHP_SELF'];
    161161                        $home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' );
     162                        $home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) );
    162163
    163164                        // Trim path info from the end and the leading home path from the
    … …  
    167168                        $req_uri = str_replace($pathinfo, '', $req_uri);
    168169                        $req_uri = trim($req_uri, '/');
    169                         $req_uri = preg_replace("|^$home_path|i", '', $req_uri);
     170                        $req_uri = preg_replace( $home_path_regex, '', $req_uri );
    170171                        $req_uri = trim($req_uri, '/');
    171172                        $pathinfo = trim($pathinfo, '/');
    172                         $pathinfo = preg_replace("|^$home_path|i", '', $pathinfo);
     173                        $pathinfo = preg_replace( $home_path_regex, '', $pathinfo );
    173174                        $pathinfo = trim($pathinfo, '/');
    174175                        $self = trim($self, '/');
    175                         $self = preg_replace("|^$home_path|i", '', $self);
     176                        $self = preg_replace( $home_path_regex, '', $self );
    176177                        $self = trim($self, '/');
    177178
  • trunk/tests/phpunit/tests/rewrite.php

    r32293 r32708  
    77 */
    88class Tests_Rewrite extends WP_UnitTestCase {
     9        private $home_url;
    910
    1011        function setUp() {
    … …  
    1920
    2021                $wp_rewrite->flush_rules();
     22
     23                $this->home_url = get_option( 'home' );
    2124        }
    2225
    … …  
    2528                $wp_rewrite->init();
    2629
     30                update_option( 'home', $this->home_url );
    2731                parent::tearDown();
    2832        }
    … …  
    7377                $this->assertEquals( 0, url_to_postid( '/example-page/example/' ) );
    7478                $this->assertEquals( 0, url_to_postid( '/example-page/ex/' ) );
     79        }
     80
     81        /**
     82         * @ticket 30438
     83         */
     84        function test_parse_request_home_path() {
     85                $home_url = home_url( '/path/' );
     86                update_option( 'home', $home_url );
     87
     88                $this->go_to( $home_url );
     89                $this->assertEquals( array(), $GLOBALS['wp']->query_vars );
     90
     91                $this->go_to( $home_url . 'page' );
     92                $this->assertEquals( array( 'page' => '', 'pagename' => 'page' ), $GLOBALS['wp']->query_vars );
     93        }
     94
     95        /**
     96         * @ticket 30438
     97         */
     98        function test_parse_request_home_path_with_regex_character() {
     99                $home_url = home_url( '/ma.ch/' );
     100                $not_a_home_url = home_url( '/match/' );
     101                update_option( 'home', $home_url );
     102
     103                $this->go_to( $home_url );
     104                $this->assertEquals( array(), $GLOBALS['wp']->query_vars );
     105
     106                $this->go_to( $home_url . 'page' );
     107                $this->assertEquals( array( 'page' => '', 'pagename' => 'page' ), $GLOBALS['wp']->query_vars );
     108
     109                $this->go_to( $not_a_home_url . 'page' );
     110                $this->assertNotEquals( array( 'page' => '', 'pagename' => 'page' ), $GLOBALS['wp']->query_vars );
     111                $this->assertEquals( array( 'page' => '', 'pagename' => 'match/page' ), $GLOBALS['wp']->query_vars );
    75112        }
    76113
Note: See TracChangeset for help on using the changeset viewer.