[wp-trac] [WordPress Trac] #64531: assertEqualHTML may ignore leading whitespace text

WordPress Trac noreply at wordpress.org
Tue Jan 20 11:37:42 UTC 2026


#64531: assertEqualHTML may ignore leading whitespace text
------------------------------+---------------------
 Reporter:  jonsurrell        |       Owner:  (none)
     Type:  defect (bug)      |      Status:  new
 Priority:  normal            |   Milestone:
Component:  Build/Test Tools  |     Version:  6.9
 Severity:  normal            |  Resolution:
 Keywords:                    |     Focuses:
------------------------------+---------------------
Changes (by jonsurrell):

 * milestone:  6.9.1 =>


Comment:

 I've been investigating the background. The whitespace trim is not part of
 the HTML5lib test suite which was the inspiration for the HTML tree
 representation.

 Whitespace trimming was added as part of the block delimiter handling. For
 example:

 {{{#!xml
 <!-- wp:block -->
   <!-- wp:nested-void /-->
   <div></div>
 <!-- /wp:block -->
 }}}

 Produces this tree with the whitespace trimmed:

 {{{
 BLOCK["core/block"]
   BLOCK["core/nested-void"]
   <div>
 }}}

 This would be the resulting tree of the same input with whitespace
 included:

 {{{
 BLOCK["core/block"]
   "
   "
   BLOCK["core/nested-void"]
   "
   "
   <div>
   "
 "
 }}}

 It seems clear to me that whitespace trimming _should not occure_ when
 block delimiters are not involved. There are several cases to consider for
 whitespace and block delimiters:

 - Between nested block delimiters
 - Leading whitespace inside an opening block delimiter
 - Trailing whitespace inside a closing block delimiter

 From an HTML perspective, the whitespace should be present in all of them.

 I believe the whitespace is preserved when the content is passed to a
 block's `render_callback`.

 It's simplest to remove the unexpected trimming everywhere. The only
 reason to avoid that is to ensure this remains ergonomic for writing block
 tests. It's worth noting that the handling just needs to match in most
 cases, so blocks could run into problems for cases where the HTML inside
 block delimiters is not indented equally. Whether that's relevant or not
 really depends on the block and is beyond the scope of what this assertion
 handles.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64531#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list