Make WordPress Core

Ticket #39373: 39373.patch

File 39373.patch, 1.9 KB (added by ivankristianto, 8 years ago)

Check if the $url is from current domain

  • tests/phpunit/tests/rewrite.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    389389                $this->assertInternalType( 'array', $rewrite_rules );
    390390                $this->assertNotEmpty( $rewrite_rules );
    391391        }
     392
     393        /**
     394         * @ticket 39373
     395         */
     396        public function test_url_to_postid_from_external_url(){
     397                $this->set_permalink_structure( '/%category%/%postname%/' );
     398                $cat1 = wp_create_category( 'something' );
     399                self::factory()->post->create( array( 'post_title' => 'External URL', 'post_type' => 'post', 'post_name' => 'external-url', 'post_category' => array( $cat1 ) ) );
     400
     401                $test_external = 'http://www.external-domain.com/something/external-url/';
     402                $this->assertSame( 0, url_to_postid( $test_external ) );
     403        }
    392404}
  • src/wp-includes/rewrite.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    517517        if ( !$wp_rewrite->using_index_permalinks() )
    518518                $url = str_replace( $wp_rewrite->index . '/', '', $url );
    519519
     520        // Before we truncate $url, we temporary store it
     521        $temporary_url = $url;
    520522        if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) {
    521523                // Chop off http://domain.com/[path]
    522524                $url = str_replace(home_url(), '', $url);
     
    527529                $url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) );
    528530        }
    529531
     532        // If the $url is not truncated, that means the $url is not from our current domain. Bail. @ticket 39373
     533        if( false !== strpos( $url, $temporary_url ) ){
     534                return 0;
     535        }
     536
    530537        // Trim leading and lagging slashes
    531538        $url = trim($url, '/');
    532539