[wp-trac] [WordPress Trac] #62025: Unable to use wp_kses* with JavaScript templating

WordPress Trac noreply at wordpress.org
Tue Sep 10 09:44:09 UTC 2024


#62025: Unable to use wp_kses* with JavaScript templating
------------------------------+-----------------------------
 Reporter:  jernstjernst      |      Owner:  (none)
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Formatting        |    Version:  trunk
 Severity:  normal            |   Keywords:
  Focuses:  coding-standards  |
------------------------------+-----------------------------
 We're trying to use wp_kses* with our templates that use JavaScript
 templating (e.g. https://underscorejs.org/#template, https://ejs.co/)
 syntax, however to no avail.

 **Example 1 (<%=):**

 {{{
 <?php
 $html = '<script type="text/javascript"><%= data.answer %></script>';
 echo wp_kses($html, ['script' => ['type' => true], '%' => []]);
 ?>
 }}}

 **Expected result:**

 {{{
 <script type="text/javascript"><%= data.answer %></script>
 }}}


 **Actual result:**

 {{{
 <script type="text/javascript"></script>
 }}}


 **Example 2 (<%):**

 {{{
 <?php
 $html = '<script type="text/javascript"><% print('Hello'); %></script>';
 echo wp_kses($html, ['script' => ['type' => true], '%' => []]);
 ?>
 }}}

 **Expected result:**

 {{{
 <script type="text/javascript"><% print('Hello'); %></script>
 }}}


 **Actual result:**

 {{{
 <script type="text/javascript"></script>
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62025>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list