WordPress.org

Make WordPress Core

Ticket #34144: 34144.diff

File 34144.diff, 2.1 KB (added by swissspidy, 5 years ago)
  • src/wp-includes/rewrite-functions.php

    diff --git src/wp-includes/rewrite-functions.php src/wp-includes/rewrite-functions.php
    index 9cfb89c..8dfc118 100644
    function url_to_postid( $url ) { 
    339339        $url_split = explode('?', $url);
    340340        $url = $url_split[0];
    341341
     342        // Set the correct URL scheme.
     343        $url = set_url_scheme( $url );
     344
    342345        // Add 'www.' if it is absent and should be there
    343346        if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )
    344347                $url = str_replace('://', '://www.', $url);
  • tests/phpunit/tests/rewrite.php

    diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php
    index 80f2e9a..601b4cd 100644
    class Tests_Rewrite extends WP_UnitTestCase { 
    9292                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
    9393        }
    9494
     95        function test_url_to_postid_set_url_scheme_https_to_http() {
     96                $post_id = $this->factory->post->create();
     97                $permalink = get_permalink( $post_id );
     98                $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'https' ) ) );
     99
     100                $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     101                $permalink = get_permalink( $post_id );
     102                $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'https' ) ) );
     103        }
     104
     105        function test_url_to_postid_set_url_scheme_http_to_https() {
     106                // Save server data for cleanup
     107                $is_ssl = is_ssl();
     108                $http_host = $_SERVER['HTTP_HOST'];
     109
     110                $_SERVER['HTTPS'] = 'on';
     111
     112                $post_id = $this->factory->post->create();
     113                $permalink = get_permalink( $post_id );
     114                $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'http' ) ) );
     115
     116                $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     117                $permalink = get_permalink( $post_id );
     118                $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'http' ) ) );
     119
     120                // Cleanup.
     121                $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off';
     122                $_SERVER['HTTP_HOST'] = $http_host;
     123        }
     124
    95125        function test_url_to_postid_custom_post_type() {
    96126                delete_option( 'rewrite_rules' );
    97127