Make WordPress Core


Ignore:
Timestamp:
10/09/2025 11:36:10 PM (13 months ago)
Author:
dmsnell
Message:

HTML API: Escape all submitted HTML character references.

The HTML API has relied on esc_attr() and esc_html() when setting string attribute values or the contents of modifiable text. This leads to unexpected behavior when those functions attempt to prevent double-escaping of existing character references, and it can make certain contents impossible to represent.

After this change, the HTML API will reliably escape all submitted plaintext such that it appears in the browser the way it was submitted to the HTML API, with all character references escaped. This does not change the behavior of how URL attributes are escaped.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/10143
Discussed in https://core.trac.wordpress.org/ticket/64054

Props dmsnell, jonsurrell, westonruter.
Fixes #64054.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php

    r60727 r60919  
    139139                                        ),
    140140                                ),
    141                                 'expected_wrapper'    => '<div class="has-background" style="background-image:url(&#039;https://example.com/image.jpg&#039;);background-size:cover;">Content</div>',
     141                                'expected_wrapper'    => '<div class="has-background" style="background-image:url(&apos;https://example.com/image.jpg&apos;);background-size:cover;">Content</div>',
    142142                                'wrapper'             => '<div>Content</div>',
    143143                        ),
    … …  
    156156                                        'backgroundAttachment' => 'fixed',
    157157                                ),
    158                                 'expected_wrapper'    => '<div class="has-background" style="background-image:url(&#039;https://example.com/image.jpg&#039;);background-position:50% 50%;background-repeat:no-repeat;background-size:contain;background-attachment:fixed;">Content</div>',
     158                                'expected_wrapper'    => '<div class="has-background" style="background-image:url(&apos;https://example.com/image.jpg&apos;);background-position:50% 50%;background-repeat:no-repeat;background-size:contain;background-attachment:fixed;">Content</div>',
    159159                                'wrapper'             => '<div>Content</div>',
    160160                        ),
    … …  
    170170                                        ),
    171171                                ),
    172                                 'expected_wrapper'    => '<div class="wp-block-test has-background" style="color: red;background-image:url(&#039;https://example.com/image.jpg&#039;);background-size:cover;">Content</div>',
     172                                'expected_wrapper'    => '<div class="wp-block-test has-background" style="color: red;background-image:url(&apos;https://example.com/image.jpg&apos;);background-size:cover;">Content</div>',
    173173                                'wrapper'             => '<div class="wp-block-test" style="color: red">Content</div>',
    174174                        ),
    … …  
    184184                                        ),
    185185                                ),
    186                                 'expected_wrapper'    => '<div class="wp-block-test has-background" style="color: red;font-size: 15px;background-image:url(&#039;https://example.com/image.jpg&#039;);background-size:cover;">Content</div>',
     186                                'expected_wrapper'    => '<div class="wp-block-test has-background" style="color: red;font-size: 15px;background-image:url(&apos;https://example.com/image.jpg&apos;);background-size:cover;">Content</div>',
    187187                                'wrapper'             => '<div class="wp-block-test" style="color: red;font-size: 15px;">Content</div>',
    188188                        ),
    … …  
    199199                                        ),
    200200                                ),
    201                                 'expected_wrapper'    => '<div class="has-background" classname="wp-block-test" style="background-image:url(&#039;https://example.com/image.jpg&#039;);background-size:cover;">Content</div>',
     201                                'expected_wrapper'    => '<div class="has-background" classname="wp-block-test" style="background-image:url(&apos;https://example.com/image.jpg&apos;);background-size:cover;">Content</div>',
    202202                                'wrapper'             => '<div classname="wp-block-test" style>Content</div>',
    203203                        ),
Note: See TracChangeset for help on using the changeset viewer.