Make WordPress Core

Ticket #28632: 28632.patch

File 28632.patch, 3.0 KB (added by johnbillion, 12 years ago)
  • src/wp-includes/link-template.php

     
    28422842 * @since 3.4.0
    28432843 *
    28442844 * @param string $url Absolute url that includes a scheme
    2845  * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
     2845 * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', 'relative', or 'protocol_relative'.
    28462846 * @return string $url URL with chosen scheme.
    28472847 */
    28482848function set_url_scheme( $url, $scheme = null ) {
    … …  
    28522852                $scheme = is_ssl() ? 'https' : 'http';
    28532853        } elseif ( $scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc' ) {
    28542854                $scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http';
    2855         } elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' ) {
     2855        } elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' && $scheme !== 'protocol_relative' ) {
    28562856                $scheme = is_ssl() ? 'https' : 'http';
    28572857        }
    28582858
    … …  
    28642864                $url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
    28652865                if ( $url !== '' && $url[0] === '/' )
    28662866                        $url = '/' . ltrim($url , "/ \t\n\r\0\x0B" );
     2867        } else if ( 'protocol_relative' == $scheme ) {
     2868                $url = preg_replace( '#^\w+://#', '//', $url );
    28672869        } else {
    28682870                $url = preg_replace( '#^\w+://#', $scheme . '://', $url );
    28692871        }
    … …  
    28762878         * @param string $url         The complete URL including scheme and path.
    28772879         * @param string $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
    28782880         * @param string $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
    2879          *                            'login_post', 'admin', 'rpc', or 'relative'.
     2881         *                            'login_post', 'admin', 'rpc', 'relative', or 'protocol_relative'.
    28802882         */
    28812883        return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
    28822884}
  • tests/phpunit/tests/url.php

     
    239239                        ''
    240240                );
    241241
     242                $protocol_relative_links = array(
     243                        '//wordpress.org/',
     244                        '//wordpress.org/',
     245                        '//wordpress.org/news/',
     246                        '//wordpress.org'
     247                );
     248
    242249                $forced_admin = force_ssl_admin();
    243250                $forced_login = force_ssl_login();
    244251                $i = 0;
    … …  
    246253                        $this->assertEquals( $https_links[ $i ], set_url_scheme( $link, 'https' ) );
    247254                        $this->assertEquals( $http_links[ $i ], set_url_scheme( $link, 'http' ) );
    248255                        $this->assertEquals( $relative_links[ $i ], set_url_scheme( $link, 'relative' ) );
     256                        $this->assertEquals( $protocol_relative_links[ $i ], set_url_scheme( $link, 'protocol_relative' ) );
    249257
    250258                        $_SERVER['HTTPS'] = 'on';
    251259                        $this->assertEquals( $https_links[ $i ], set_url_scheme( $link ) );