Changeset 38036
- Timestamp:
- 07/12/2016 11:31:58 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/general-template.php
r38029 r38036 2816 2816 */ 2817 2817 $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type ); 2818 $urls = array_unique( $urls ); 2819 2820 foreach ( $urls as $url ) { 2818 2819 foreach ( $urls as $key => $url ) { 2821 2820 $url = esc_url( $url, array( 'http', 'https' ) ); 2821 if ( ! $url ) { 2822 unset( $urls[ $key ] ); 2823 continue; 2824 } 2822 2825 2823 2826 if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) { 2824 2827 $parsed = wp_parse_url( $url ); 2825 2828 if ( empty( $parsed['host'] ) ) { 2829 unset( $urls[ $key ] ); 2826 2830 continue; 2827 2831 } 2828 2832 2829 if ( ! empty( $parsed['scheme'] ) ) { 2833 if ( 'dns-prefetch' === $relation_type ) { 2834 $url = '//' . $parsed['host']; 2835 } else if ( ! empty( $parsed['scheme'] ) ) { 2830 2836 $url = $parsed['scheme'] . '://' . $parsed['host']; 2831 2837 } else { … … 2834 2840 } 2835 2841 2836 printf( "<link rel='%s' href='%s'>\r\n", $relation_type, $url ); 2842 $urls[ $key ] = $url; 2843 } 2844 2845 $urls = array_unique( $urls ); 2846 2847 foreach ( $urls as $url ) { 2848 printf( "<link rel='%s' href='%s'>\n", $relation_type, $url ); 2837 2849 } 2838 2850 } -
trunk/tests/phpunit/tests/general/resourceHints.php
r37951 r38036 32 32 33 33 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"; 35 35 36 36 $this->expectOutputString( $expected ); … … 40 40 41 41 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"; 46 46 47 47 add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ), 10, 2 ); … … 57 57 if ( 'dns-prefetch' === $method ) { 58 58 $hints[] = 'http://wordpress.org'; 59 $hints[] = 'https://wordpress.org'; 60 $hints[] = 'htps://wordpress.org'; // Invalid URLs should be skipped. 59 61 $hints[] = 'https://google.com'; 60 62 $hints[] = '//make.wordpress.org'; 63 $hints[] = 'https://wordpress.org/plugins/'; 61 64 } 62 65 … … 65 68 66 69 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"; 71 74 72 75 add_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ), 10, 2 ); … … 84 87 $hints[] = 'http://jobs.wordpress.net'; 85 88 $hints[] = '//core.trac.wordpress.org'; 89 $hints[] = 'htps://wordpress.org'; // Invalid URLs should be skipped. 86 90 } 87 91 … … 90 94 91 95 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"; 94 98 95 99 add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ), 10, 2 ); … … 111 115 112 116 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"; 115 119 116 120 $args = array( … … 130 134 131 135 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"; 134 138 135 139 $args = array(
Note: See TracChangeset
for help on using the changeset viewer.