Make WordPress Core

Opened 2 weeks ago

Last modified 12 days ago

#62522 reopened defect (bug)

Whitespace can trip up `WP_Interactivity_API::_process_directives()` when there is a `core/button` `text` block binding

Reported by: wongjn's profile wongjn Owned by: jonsurrell's profile jonsurrell
Milestone: 6.7.2 Priority: normal
Severity: normal Version: 6.6
Component: HTML API Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Steps to reproduce

  1. Set WP_DEBUG to true in wp-config.php.
  2. Install clean WordPress 6.7.1.
  3. Activate Twenty Twenty-Four theme.
  4. Replace /wp-content/themes/twentytwentyfour/templates/single.html with:
    <!-- wp:query {"queryId":0,"query":{"perPage":10,"pages":"0","offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[],"format":[]},"enhancedPagination":true,"layout":{"type":"constrained"}} -->
    <div class="wp-block-query">
    	<!-- wp:post-template {"layout":{"type":"default","columnCount":3}} -->
    		<!-- wp:buttons -->
    		<div class="wp-block-buttons"><!-- wp:button {"metadata":{"bindings":{"text":{"source":"core/post-meta","args":{"key":"foo"}}}}} -->
    			<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Get Tickets</a></div>
    			<!-- /wp:button -->
    		</div>
    		<!-- /wp:buttons -->
    	<!-- /wp:post-template -->
    </div>
    <!-- /wp:query -->
    
  5. Append the following to /wp-content/themes/twentytwentyfour/functions.php:
    function _test() {
            $args = array(
                    'type'              => 'string',
                    'single'            => true,
                    'sanitize_callback' => '',
                    'show_in_rest'      => true,
                    'revisions_enabled' => true,
            );
            register_post_meta( 'post', 'foo', $args );
            update_post_meta(1, 'foo', 'test' );
    }
    add_action( 'init', '_test' );
    
  6. Navigate to /index.php?p=1 (the Hello World post) in your browser.
  7. Notice no errors.
  8. Replace /wp-content/themes/twentytwentyfour/templates/single.html with:
    <!-- wp:query {"queryId":0,"query":{"perPage":10,"pages":"0","offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[],"format":[]},"enhancedPagination":true,"layout":{"type":"constrained"}} -->
    <div class="wp-block-query">
    	<!-- wp:post-template {"layout":{"type":"default","columnCount":3}} -->
    		<!-- wp:buttons -->
    		<div class="wp-block-buttons">
    <!-- wp:button {"metadata":{"bindings":{"text":{"source":"core/post-meta","args":{"key":"foo"}}}}} -->
    			<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Get Tickets</a></div>
    			<!-- /wp:button -->
    		</div>
    		<!-- /wp:buttons -->
    	<!-- /wp:post-template -->
    </div>
    <!-- /wp:query -->
    
  9. Navigate to /index.php?p=1 (the Hello World post) in your browser.
  10. Notice an error displayed:
    Notice: Function WP_Interactivity_API::_process_directives was called <strong>incorrectly</strong>. Interactivity directives failed to process in "" due to a missing "LI" end tag. Please see <a href="https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 6.6.0.) in /path/to/wordpress/wp-includes/functions.php on line 6114
    

Other remarkables

  • When the error is displayed, the markup has some HTML in uppercase:
    <DIV class="wp-block-button"><a class="wp-block-button__link wp-element-button">test</a></DIV>
    
  • Any amount of newline/whitespace seems to cause the error:
    <!-- wp:query {"queryId":0,"query":{"perPage":10,"pages":"0","offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[],"format":[]},"enhancedPagination":true,"layout":{"type":"constrained"}} -->
    <div class="wp-block-query">
    	<!-- wp:post-template {"layout":{"type":"default","columnCount":3}} -->
    		<!-- wp:buttons -->
    		<div class="wp-block-buttons">
    			<!-- wp:button {"metadata":{"bindings":{"text":{"source":"core/post-meta","args":{"key":"foo"}}}}} -->
    			<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Get Tickets</a></div>
    			<!-- /wp:button -->
    		</div>
    		<!-- /wp:buttons -->
    	<!-- /wp:post-template -->
    </div>
    <!-- /wp:query -->
    
  • Including the same snippet from _Copy All Blocks_ command in the editor, but with a newline before the opening core/button comment:
    <!-- wp:query {"queryId":0,"query":{"perPage":10,"pages":"0","offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[],"format":[]},"enhancedPagination":true,"layout":{"type":"constrained"}} -->
    <div class="wp-block-query"><!-- wp:post-template {"layout":{"type":"default","columnCount":3}} -->
    	<!-- wp:buttons {"layout":{"type":"flex"}} -->
    	<div class="wp-block-buttons">
    <!-- wp:button {"metadata":{"bindings":{"text":{"source":"core/post-meta","args":{"key":"foo"}}}}} -->
    	<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Get Tickets</a></div>
    	<!-- /wp:button --></div>
    	<!-- /wp:buttons -->
    	<!-- /wp:post-template --></div>
    	<!-- /wp:query -->
    

Change History (8)

This ticket was mentioned in PR #7893 on WordPress/wordpress-develop by @santosguillamot.


13 days ago
#1

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/62522

Fixes a bug where processing the button block with bindings returns the HTML wrapper DIV in uppercase, which breaks other processing, like the Interactivity API directives.

#2 @cbravobernal
13 days ago

  • Milestone changed from Awaiting Review to 6.8
  • Version changed from 6.7.1 to 6.6

This ticket was mentioned in PR #7897 on WordPress/wordpress-develop by @jonsurrell.


13 days ago
#3

  • Keywords has-unit-tests added

Ensure uppercase tag names are matched correctly by the tag processor.

Ticket 62522 describes an issue where a whitespace-prefixed tag was causing problems. With the help of @SantosGuillamot and @cbravobernal, this was narrowed down to an uppercase open tag name prefixed by whitespace not being found in the tag processor.

There was a missing "D" in the character list used by strspn to find tag openers, causing tags starting with D to be skipped by the tag processor in some circumstances.

Add tests to ensure variations of uppper and lowercase tag names openers and closers are recognized.

This only appears in rare cases because the tag name must appear in the correct position (preceded by whitespace) and must start with an uppercase D. Casing is not relevant for tag names, and most tag names are lowercase in the wild.

Trac ticket: https://core.trac.wordpress.org/ticket/62522

Closes https://github.com/WordPress/wordpress-develop/pull/7893 (supersedes).

#4 @jonsurrell
13 days ago

  • Component changed from Interactivity API to HTML API
  • Milestone changed from 6.8 to 6.7.2
  • Owner set to jonsurrell
  • Status changed from new to assigned

I'm changing the milestone to 6.7.2, I'd like https://github.com/WordPress/wordpress-develop/pull/7897 to be considered for inclusion.

#5 @cbravobernal
12 days ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 59464:

HTML API: Recognize all uppercase tag names in tag processor.

Fixes a missing "D" in the character list used by strspn to find tag openers, causing tags starting with D to be skipped by the tag processor in some circumstances.

Follow-up to [58613].

Props jonsurrell, santosguillamot, wongjn, cbravobernal.
Fixes #62522.

#8 @jonsurrell
12 days ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening to consider for 6.7.2.

Note: See TracTickets for help on using tickets.