#62025 closed defect (bug) (duplicate)
Unable to use wp_kses* with JavaScript templating
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 1.0 |
| Component: | Formatting | Keywords: | |
| Focuses: | Cc: |
Description
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>
Change History (3)
#1
@
21 months ago
- Focuses coding-standards removed
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
- Version changed from trunk to 1.0
Note: See
TracTickets for help on using
tickets.
This is technically working as intended, as KSES is supposed to strip invalid/unsupported HTML markup. It is not meant to be used on things like Underscore templates.
See #30920 where this was previously discussed.