Make WordPress Core


Ignore:
Timestamp:
10/28/2025 09:35:53 PM (13 months ago)
Author:
SergeyBiryukov
Message:

Script Loader: Consistently escape the style handle in WP_Styles::do_item().

Includes moving most of the escaping as late as possible when the <link> tag is being constructed.

Follow-up to [29956], [36550], [43564], [46164].

Props georgestephanis, westonruter, azaozz, jonsurrell, XecurAbhijeet, SergeyBiryukov.
See #30036.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r61008 r61084  
    9393
    9494        /**
     95         * Test assorted handles to make sure they are output correctly.
     96         *
     97         * @dataProvider data_awkward_handles_are_supported_consistently
     98         *
     99         * @ticket 30036
     100         */
     101        public function test_awkward_handles_are_supported_consistently( $handle ) {
     102                wp_enqueue_style( $handle, 'example.com', array(), null );
     103
     104                $expected = "<link rel='stylesheet' id='$handle-css' href='http://example.com' type='text/css' media='all' />\n";
     105
     106                $this->assertSame( $expected, get_echo( 'wp_print_styles' ) );
     107        }
     108
     109        /**
     110         * Data provider.
     111         *
     112         * @return array<string, string[]>
     113         */
     114        public function data_awkward_handles_are_supported_consistently() {
     115                return array(
     116                        'some spaces'       => array( 'with some spaces' ),
     117                        'snowman'           => array( 'with-☃-snowman' ),
     118                        'trailing space'    => array( 'with-trailing-space ' ),
     119                        'leading space'     => array( ' with-leading-space' ),
     120                        'an "ironic" title' => array( 'an &quot;ironic&quot; title' ),
     121                );
     122        }
     123
     124        /**
    95125         * Test the different protocol references in wp_enqueue_style
    96126         *
Note: See TracChangeset for help on using the changeset viewer.