[wp-trac] [WordPress Trac] #44571: force_balance_tags breaks JavaScript

WordPress Trac noreply at wordpress.org
Sun Sep 22 05:18:47 UTC 2024


#44571: force_balance_tags breaks JavaScript
-----------------------------+------------------------------
 Reporter:  yellowafterlife  |       Owner:  (none)
     Type:  defect (bug)     |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Shortcodes       |     Version:  4.9.7
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by dmsnell):

 Hi @soulseekah - I'm exploring replacing the logic from
 `force_balance_tags()` with the new `WP_HTML_Processor::normalize()` and
 it seems to handle the cases you've raised here.

 {{{#!php
 <?php
 echo force_balance_tags( '<script>console.log("extest:", 0<=1);</script>'
 );
 // <script>console.log("extest:", 0<=1);</script>

 echo force_balance_tags( '<p>hello' );
 // <p>hello</p>

 echo force_balance_tags( '<p>hello</p>' );
 // <p>hello</p>
 }}}

 since the logic is based on the HTML API it should be robust regardless of
 the input. no more guessing! as of WordPress 6.7.0 there will see be a
 marginal number of input HTML documents not supported by the HTML API;
 these will fall back to the legacy behavior of `force_balance_tags()` (or
 perhaps we'll replace the custom parsing with the Tag Processor which is
 also based on the HTML spec but doesn't know HTML structure).

 https://github.com/WordPress/wordpress-develop/pull/7409

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


More information about the wp-trac mailing list