Make WordPress Core


Ignore:
Timestamp:
03/24/2025 02:51:19 PM (8 months ago)
Author:
joemcgill
Message:

Interactivity API: Apply the same directive name restrictions as the client.

This adds the same logic to filter directive data attributes to ignore invalid data attributes that is applied in the client to avoid processing directives on the server that will not be processed in the client.

Props jonsurrell, SirLouen.
Fixes #62426.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php

    r59477 r60070  
    15861586        );
    15871587    }
     1588
     1589    /**
     1590     * Ensures that directives with invalid attribute names are ignored.
     1591     *
     1592     * @ticket 62426
     1593     */
     1594    public function test_invalid_directive_names_are_ignored() {
     1595        $html = <<<HTML
     1596            <div data-wp-interactive="test" data-wp-context='{ "t": true }'>
     1597                <br data-wp-class--allowed="context.t">
     1598                <br data-wp-class--dis:allowed="context.t">
     1599                <br data-wp-class--[disallowed]="context.t">
     1600            </div>
     1601HTML;
     1602
     1603        $processed_html = $this->interactivity->process_directives( $html );
     1604        $this->assertStringContainsString( 'class="allowed"', $processed_html );
     1605        $this->assertStringNotContainsString( 'class="dis:allowed"', $processed_html );
     1606        $this->assertStringNotContainsString( 'class="[disallowed]"', $processed_html );
     1607    }
    15881608}
Note: See TracChangeset for help on using the changeset viewer.