WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/12/2016 11:31:58 AM (4 years ago)
Author:
ocean90
Message:

Resource Hints: Remove schemes from dns-prefetch resource hint outputs.

"wordpress.org", "http://wordpress.org", and "https://wordpress.org" should all have the same DNS lookup.
Also, replace \r\n with \n and ensure that invalid URLs are skipped.

Props niallkennedy, peterwilsoncc.
Fixes #37240.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/general/resourceHints.php

    r37951 r38036  
    3232
    3333    function test_should_have_defaults_on_frontend() {
    34         $expected = "<link rel='preconnect' href='http://s.w.org'>\r\n";
     34        $expected = "<link rel='preconnect' href='http://s.w.org'>\n";
    3535
    3636        $this->expectOutputString( $expected );
     
    4040
    4141    function test_dns_prefetching() {
    42         $expected = "<link rel='dns-prefetch' href='http://wordpress.org'>\r\n" .
    43                     "<link rel='dns-prefetch' href='https://google.com'>\r\n" .
    44                     "<link rel='dns-prefetch' href='make.wordpress.org'>\r\n" .
    45                     "<link rel='preconnect' href='http://s.w.org'>\r\n";
     42        $expected = "<link rel='dns-prefetch' href='//wordpress.org'>\n" .
     43                    "<link rel='dns-prefetch' href='//google.com'>\n" .
     44                    "<link rel='dns-prefetch' href='//make.wordpress.org'>\n" .
     45                    "<link rel='preconnect' href='http://s.w.org'>\n";
    4646
    4747        add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ), 10, 2 );
     
    5757        if ( 'dns-prefetch' === $method ) {
    5858            $hints[] = 'http://wordpress.org';
     59            $hints[] = 'https://wordpress.org';
     60            $hints[] = 'htps://wordpress.org'; // Invalid URLs should be skipped.
    5961            $hints[] = 'https://google.com';
    6062            $hints[] = '//make.wordpress.org';
     63            $hints[] = 'https://wordpress.org/plugins/';
    6164        }
    6265
     
    6568
    6669    function test_prerender() {
    67         $expected = "<link rel='preconnect' href='http://s.w.org'>\r\n" .
    68                     "<link rel='prerender' href='https://make.wordpress.org/great-again'>\r\n" .
    69                     "<link rel='prerender' href='http://jobs.wordpress.net'>\r\n" .
    70                     "<link rel='prerender' href='//core.trac.wordpress.org'>\r\n";
     70        $expected = "<link rel='preconnect' href='http://s.w.org'>\n" .
     71                    "<link rel='prerender' href='https://make.wordpress.org/great-again'>\n" .
     72                    "<link rel='prerender' href='http://jobs.wordpress.net'>\n" .
     73                    "<link rel='prerender' href='//core.trac.wordpress.org'>\n";
    7174
    7275        add_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ), 10, 2 );
     
    8487            $hints[] = 'http://jobs.wordpress.net';
    8588            $hints[] = '//core.trac.wordpress.org';
     89            $hints[] = 'htps://wordpress.org'; // Invalid URLs should be skipped.
    8690        }
    8791
     
    9094
    9195    function test_parse_url_dns_prefetch() {
    92         $expected = "<link rel='dns-prefetch' href='http://make.wordpress.org'>\r\n" .
    93                     "<link rel='preconnect' href='http://s.w.org'>\r\n";
     96        $expected = "<link rel='dns-prefetch' href='//make.wordpress.org'>\n" .
     97                    "<link rel='preconnect' href='http://s.w.org'>\n";
    9498
    9599        add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ), 10, 2 );
     
    111115
    112116    function test_dns_prefetch_styles() {
    113         $expected = "<link rel='dns-prefetch' href='http://fonts.googleapis.com'>\r\n" .
    114                     "<link rel='preconnect' href='http://s.w.org'>\r\n";
     117        $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com'>\n" .
     118                    "<link rel='preconnect' href='http://s.w.org'>\n";
    115119
    116120        $args = array(
     
    130134
    131135    function test_dns_prefetch_scripts() {
    132         $expected = "<link rel='dns-prefetch' href='http://fonts.googleapis.com'>\r\n" .
    133                     "<link rel='preconnect' href='http://s.w.org'>\r\n";
     136        $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com'>\n" .
     137                    "<link rel='preconnect' href='http://s.w.org'>\n";
    134138
    135139        $args = array(
Note: See TracChangeset for help on using the changeset viewer.