Make WordPress Core

Ticket #30438: 30438.diff

File 30438.diff, 2.5 KB (added by akirk, 10 years ago)
  • src/wp-includes/class-wp.php

     
    164164                        // requested permalink.
    165165                        $req_uri = str_replace($pathinfo, '', $req_uri);
    166166                        $req_uri = trim($req_uri, '/');
    167                         $req_uri = preg_replace("|^$home_path|i", '', $req_uri);
     167                        $req_uri = preg_replace("|^" . preg_quote($home_path, "|") . "|i", '', $req_uri);
    168168                        $req_uri = trim($req_uri, '/');
    169169                        $pathinfo = trim($pathinfo, '/');
    170                         $pathinfo = preg_replace("|^$home_path|i", '', $pathinfo);
     170                        $pathinfo = preg_replace("|^" . preg_quote($home_path, "|") . "|i", '', $pathinfo);
    171171                        $pathinfo = trim($pathinfo, '/');
    172172                        $self = trim($self, '/');
    173                         $self = preg_replace("|^$home_path|i", '', $self);
     173                        $self = preg_replace("|^" . preg_quote($home_path, "|") . "|i", '', $self);
    174174                        $self = trim($self, '/');
    175175
    176176                        // The requested permalink is in $pathinfo for path info requests and
  • tests/phpunit/tests/rewrite.php

     
    66 * @group rewrite
    77 */
    88class Tests_Rewrite extends WP_UnitTestCase {
     9        private $home_url;
    910
    1011        function setUp() {
    1112                global $wp_rewrite;
     
    1819                create_initial_taxonomies();
    1920
    2021                $wp_rewrite->flush_rules();
     22
     23                $this->home_url = get_option( 'home' );
    2124        }
    2225
    2326        function tearDown() {
     
    2427                global $wp_rewrite;
    2528                $wp_rewrite->init();
    2629
     30                update_option( 'home', $this->home_url );
    2731                parent::tearDown();
    2832        }
    2933
     
    7478                $this->assertEquals( 0, url_to_postid( '/example-page/ex/' ) );
    7579        }
    7680
     81        function test_parse_request_home_path() {
     82                $home_url = home_url( '/path/' );
     83                update_option( 'home', $home_url );
     84
     85                $this->go_to( $home_url );
     86                $this->assertEquals( array(), $GLOBALS['wp']->query_vars );
     87
     88                $this->go_to( $home_url . 'page');
     89                $this->assertEquals( array('page' => '', 'pagename' => 'page'), $GLOBALS['wp']->query_vars );
     90        }
     91
     92        function test_parse_request_home_path_with_regexchar() {
     93                $home_url = home_url( '/pa+th/' );
     94                update_option( 'home', $home_url );
     95
     96                $this->go_to( $home_url );
     97                $this->assertEquals( array(), $GLOBALS['wp']->query_vars );
     98
     99                $this->go_to( $home_url . 'page');
     100                $this->assertEquals( array('page' => '', 'pagename' => 'page'), $GLOBALS['wp']->query_vars );
     101        }
     102
    77103        function test_url_to_postid_dupe_path() {
    78104                update_option( 'home', home_url('/example/') );
    79105