Search code examples
jsongrailsgsp

Grails 2.3 expression output error in g:javascript environment


I recently updated my Grails installation from 2.2 to 2.3.1 and encountered an error while trying to use a groovy expression inside a <g:javascript> environment to get some json data structure.

This is an example:

<g:javascript>
  var foo = ${ bar as grails.converters.JSON };
  doSomeStuff();
</g:javascript>

This will escape the whole JSON-string to unicode chars (\u005b\u007bid:1\u002c name:.....). How is it possible to get the raw string. As the documentation pointed out: I tried using the raw() keyword. But had no luck. I didn't changed any of my XSS-related configs. Thats my config:

grails.views.default.codec = "none"
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"

Edit:

My temporary solution till this bug is fixed:

$.parseJSON(decodeURIComponent(uglyUnicodeString))


Solution

  • This is a bug. See this issue and the linked ones:

    http://jira.grails.org/browse/GRAILS-10641