Make WordPress Core

Changeset 54348


Ignore:
Timestamp:
09/28/2022 02:57:55 PM (21 months ago)
Author:
audrasjb
Message:

Script Loader: Prevent double space between attributes in WP_Styles class.

This changeset prevents <link /> elements to display a double space between attributes when no title attribute is provided.

Props elten, audrasjb, whaze, SergeyBiryukov.
Fixes #56675.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-styles.php

    r54254 r54348  
    225225
    226226        $rel   = isset( $obj->extra['alt'] ) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
    227         $title = isset( $obj->extra['title'] ) ? sprintf( "title='%s'", esc_attr( $obj->extra['title'] ) ) : '';
     227        $title = isset( $obj->extra['title'] ) ? sprintf( " title='%s'", esc_attr( $obj->extra['title'] ) ) : '';
    228228
    229229        $tag = sprintf(
    230             "<link rel='%s' id='%s-css' %s href='%s'%s media='%s' />\n",
     230            "<link rel='%s' id='%s-css'%s href='%s'%s media='%s' />\n",
    231231            $rel,
    232232            $handle,
     
    260260
    261261            $rtl_tag = sprintf(
    262                 "<link rel='%s' id='%s-rtl-css' %s href='%s'%s media='%s' />\n",
     262                "<link rel='%s' id='%s-rtl-css'%s href='%s'%s media='%s' />\n",
    263263                $rel,
    264264                $handle,
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r52754 r54348  
    6464
    6565        $ver       = get_bloginfo( 'version' );
    66         $expected  = "<link rel='stylesheet' id='no-deps-no-version-css'  href='http://example.com?ver=$ver' type='text/css' media='all' />\n";
    67         $expected .= "<link rel='stylesheet' id='no-deps-version-css'  href='http://example.com?ver=1.2' type='text/css' media='all' />\n";
    68         $expected .= "<link rel='stylesheet' id='no-deps-null-version-css'  href='http://example.com' type='text/css' media='all' />\n";
    69         $expected .= "<link rel='stylesheet' id='no-deps-null-version-print-media-css'  href='http://example.com' type='text/css' media='print' />\n";
     66        $expected  = "<link rel='stylesheet' id='no-deps-no-version-css' href='http://example.com?ver=$ver' type='text/css' media='all' />\n";
     67        $expected .= "<link rel='stylesheet' id='no-deps-version-css' href='http://example.com?ver=1.2' type='text/css' media='all' />\n";
     68        $expected .= "<link rel='stylesheet' id='no-deps-null-version-css' href='http://example.com' type='text/css' media='all' />\n";
     69        $expected .= "<link rel='stylesheet' id='no-deps-null-version-print-media-css' href='http://example.com' type='text/css' media='print' />\n";
    7070
    7171        $this->assertSame( $expected, get_echo( 'wp_print_styles' ) );
     
    8787
    8888        $ver      = get_bloginfo( 'version' );
    89         $expected = "<link rel='stylesheet' id='no-deps-no-version-css'  href='http://example.com?ver=$ver' media='all' />\n";
     89        $expected = "<link rel='stylesheet' id='no-deps-no-version-css' href='http://example.com?ver=$ver' media='all' />\n";
    9090
    9191        $this->assertSame( $expected, get_echo( 'wp_print_styles' ) );
     
    108108        // Try with an HTTP reference.
    109109        wp_enqueue_style( 'reset-css-http', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
    110         $expected .= "<link rel='stylesheet' id='reset-css-http-css'  href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     110        $expected .= "<link rel='stylesheet' id='reset-css-http-css' href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
    111111
    112112        // Try with an HTTPS reference.
    113113        wp_enqueue_style( 'reset-css-https', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
    114         $expected .= "<link rel='stylesheet' id='reset-css-https-css'  href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     114        $expected .= "<link rel='stylesheet' id='reset-css-https-css' href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
    115115
    116116        // Try with an automatic protocol reference (//).
    117117        wp_enqueue_style( 'reset-css-doubleslash', '//yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
    118         $expected .= "<link rel='stylesheet' id='reset-css-doubleslash-css'  href='//yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     118        $expected .= "<link rel='stylesheet' id='reset-css-doubleslash-css' href='//yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
    119119
    120120        // Try with a local resource and an automatic protocol reference (//).
    121121        $url = '//my_plugin/style.css';
    122122        wp_enqueue_style( 'plugin-style', $url );
    123         $expected .= "<link rel='stylesheet' id='plugin-style-css'  href='$url?ver=$ver' type='text/css' media='all' />\n";
     123        $expected .= "<link rel='stylesheet' id='plugin-style-css' href='$url?ver=$ver' type='text/css' media='all' />\n";
    124124
    125125        // Try with a bad protocol.
    126126        wp_enqueue_style( 'reset-css-ftp', 'ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
    127         $expected .= "<link rel='stylesheet' id='reset-css-ftp-css'  href='{$wp_styles->base_url}ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     127        $expected .= "<link rel='stylesheet' id='reset-css-ftp-css' href='{$wp_styles->base_url}ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
    128128
    129129        // Go!
     
    148148        $style .= '}';
    149149
    150         $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     150        $expected  = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
    151151        $expected .= "<style id='handle-inline-css' type='text/css'>\n";
    152152        $expected .= "$style\n";
     
    177177        $style .= '}';
    178178
    179         $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     179        $expected  = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
    180180        $expected .= "<style id='handle-inline-css' type='text/css'>\n";
    181181        $expected .= "$style\n";
     
    259259        $style2 .= '}';
    260260
    261         $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     261        $expected  = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
    262262        $expected .= "<style id='handle-inline-css' type='text/css'>\n";
    263263        $expected .= "$style1\n";
     
    288288        $style .= '</style>';
    289289
    290         $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     290        $expected  = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
    291291        $expected .= "$style\n";
    292292
     
    306306    public function test_unnecessary_style_tags() {
    307307
    308         $expected = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     308        $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
    309309
    310310        wp_enqueue_style( 'handle', 'http://example.com', array(), 1 );
     
    321321        $expected = <<<CSS
    322322<!--[if IE]>
    323 <link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />
     323<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />
    324324<style id='handle-inline-css' type='text/css'>
    325325a { color: blue; }
     
    351351        $style = 'a { color: blue; }';
    352352
    353         $expected  = "<link rel='stylesheet' id='handle-one-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
    354         $expected .= "<link rel='stylesheet' id='handle-two-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     353        $expected  = "<link rel='stylesheet' id='handle-one-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
     354        $expected .= "<link rel='stylesheet' id='handle-two-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
    355355        $expected .= "<style id='handle-three-inline-css' type='text/css'>\n";
    356356        $expected .= "$style\n";
Note: See TracChangeset for help on using the changeset viewer.