Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#62522 closed defect (bug) (fixed)

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

Reported by: wongjn Owned by: desrosj
Priority: normal Milestone: 6.7.2
Component: HTML API Version: 6.6
Severity: normal Keywords: has-patch has-unit-tests dev-reviewed
Cc: Focuses:

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 (13)

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


2 years 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
2 years ago

  • Milestone Awaiting Review → 6.8
  • Version 6.7.1 → 6.6

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


2 years 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
2 years ago

  • Component Interactivity API → HTML API
  • Milestone 6.8 → 6.7.2
  • Owner set to jonsurrell
  • Status new → 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
2 years ago

  • Resolution → fixed
  • Status assigned → 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
2 years ago

  • Resolution fixed
  • Status closed → reopened

Reopening to consider for 6.7.2.

This ticket was mentioned in ​Slack in #core by jorbin. ​View the logs.


2 years ago

#10 @jorbin
2 years ago

  • Keywords dev-feedback added

#11 @desrosj
2 years ago

  • Owner changed from jonsurrell to desrosj
  • Status reopened → reviewing

#12 @desrosj
2 years ago

  • Keywords dev-reviewed added; dev-feedback removed

Looks good to backport.

#13 @desrosj
2 years ago

  • Resolution → fixed
  • Status reviewing → closed

In 59537:

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].

Reviewed by desrosj.
Merges [59464] to the 6.7 branch.

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

Note: See TracTickets for help on using tickets.