Make WordPress Core


Ignore:
Timestamp:
06/13/2024 08:55:47 AM (17 months ago)
Author:
audrasjb
Message:

HTML API: Revert using regex in block bindings HTML replacement logic.

This changeset reverts part of the changes made in [58298] to avoid using regex that can cause potential bugs. It is indeed safer to revert these changes for now and do the refactoring once the HTML API supports CSS selectors and provides a way to set inner content.

It also adds a unit test to cover the regression experienced in https://github.com/WordPress/gutenberg/issues/62347.

Follow-up to [58298].

Props santosguillamot, gziolo.
Fixes #61385.
See #61351.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-bindings/render.php

    r58289 r58398  
    237237
    238238    /**
     239     * Tests that including symbols and numbers works well with bound attributes.
     240     *
     241     * @ticket 61385
     242     *
     243     * @covers WP_Block::process_block_bindings
     244     */
     245    public function test_using_symbols_in_block_bindings_value() {
     246        $get_value_callback = function () {
     247            return '$12.50';
     248        };
     249
     250        register_block_bindings_source(
     251            self::SOURCE_NAME,
     252            array(
     253                'label'              => self::SOURCE_LABEL,
     254                'get_value_callback' => $get_value_callback,
     255            )
     256        );
     257
     258        $block_content = <<<HTML
     259<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source"}}}} -->
     260<p>Default content</p>
     261<!-- /wp:paragraph -->
     262HTML;
     263        $parsed_blocks = parse_blocks( $block_content );
     264        $block         = new WP_Block( $parsed_blocks[0] );
     265        $result        = $block->render();
     266
     267        $this->assertSame(
     268            '<p>$12.50</p>',
     269            trim( $result ),
     270            'The block content should properly show the symbol and numbers.'
     271        );
     272    }
     273
     274    /**
    239275     * Tests if the `__default` attribute is replaced with real attribues for
    240276     * pattern overrides.
Note: See TracChangeset for help on using the changeset viewer.