4

I'm trying to use the Velocity engine embedded in Atlassian's products (and exposed through com.atlassian.templaterenderer) to substitute a JSON value into a template.

In the template, this looks a bit like the following:

<script>
  foo = $foo
</script>

However, when I render the template with "foo" mapped to a string ["bar", "baz"], the output is the following:

<script>
  foo = [&quot;bar&quot;, &quot;baz&quot;]
</script>

How can this be avoided?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441

2 Answers2

6

Atlassian has an event handler which performs escaping on any variable with a name not ending with WithHtml.

Thus:

<script>
foo = $fooWithHtml
</script>

expands as desired.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
1

This is not a default behavior, looks like you have EscapeHtmlReference event handler registered either in your velocity.properties or in java initialization. More details on event handlers here.

serg
  • 109,619
  • 77
  • 317
  • 330