WordPress.org

Make WordPress Core

Opened 2 years ago

#40899 new defect (bug)

'&' Is always escaped in the JavaScript template.

Reported by: tmatsuur Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.5
Component: General Keywords:
Focuses: Cc:
PR Number:

Description

When I tried the JavaScript template, '&' was always escaped.

Source:

<script type="text/template" id="tmpl-fields">
<p>&</p>
<p>Unscaped: {{{data.value}}}</p>
<p>Escaped: {{data.value}}</p>
</script>
<script type="text/javascript">
( function($) {
	$(document).ready( function () {
		var template = wp.template( 'fields' );
		$( '.widget_search' ).after( template( { value: "W<i>o</i>&r'l\"d" } ) );
	} );
} )( jQuery );
</script>

Rendering:

<p>&amp;</p>
<p>Unscaped: W<i>o</i>&amp;r'l"d</p>
<p>Escaped: W&lt;i&gt;o&lt;/i&gt;&amp;r'l"d</p>

While checking the interpolation of the variable, '&' was always converted to '& amp;'.
Is this a specification or a bug?

Change History (0)

Note: See TracTickets for help on using tickets.