Skip to content

Commit

Permalink
GRAILS-10985: Raw encoder should return a copy of a String that is ma…
Browse files Browse the repository at this point in the history
…rked as "raw"
  • Loading branch information
lhotari committed Jan 14, 2014
1 parent 630ed76 commit c00397b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ public boolean isSafe() {
* @see org.codehaus.groovy.grails.support.encoding.Encoder#encode(java.lang.Object)
*/
public Object encode(Object o) {
return o;
if(o instanceof String) {
// create a new copy of the String instance
return new String((String)o);
} else if(o instanceof CharSequence) {
// convert CharSequence to String so that we have a new instance
return String.valueOf(o);
} else {
return o;
}
}

/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,16 @@ class TestUrlMappings {
request.setAttribute("org.codehaus.grails.INCLUDED_JS_LIBRARIES", ['test'])
assertOutputEquals('''<script type="text/javascript">\r\nvar value='<>';\r\n</script>\r\n''', template)
}


// GRAILS-10985
void testJavascriptExpressionRawAndEscaped() {
withConfig("grails.views.default.codec='HTML'") {
def template = '''<g:javascript>var value='${raw('<>'.intern())}${'<>'.intern()}';</g:javascript>'''
request.setAttribute("org.codehaus.grails.INCLUDED_JS_LIBRARIES", ['test'])
assertOutputEquals('''<script type="text/javascript">\r\nvar value='<>\\u003c\\u003e';\r\n</script>\r\n''', template)
}
}

void testJavascriptExpressionNoneDefaultCodecLegacySettings() {
withConfig("grails.views.default.codec='none'") {
def template = '''<g:javascript>var value='${'<>'}';</g:javascript>'''
Expand Down

0 comments on commit c00397b

Please sign in to comment.