This domo shows strange behavior of Grails 4 GSP double encoding prevention.
$ ./gradlew bootRun
Browse to http://localhost:8080/demo
- Create new Grails 4 app via IntelliJ IDEA
- Create Controller: put two Strings
amp1: '&'andamp2: '&'.encodeAsHTML()to the model - Create GSP-View: output each String with
${…}and${raw(…)}and test the Strings in the view for equality. - don't change any default settings
- all outputs of the strings in the model are equal
- … exactly if
amp1 == amp2istrue
amp1 == amp2istrueaccording to<g:if>&{amp1}is outputted as&amp;in the HTML source → shows up in the browser as "&"&{amp2}is outputted as&in the HTML source → shows up in the browser as "&"
Grails 2.3 includes double encoding prevention so that when an expression is evaluated, it will not encode if the data has already been encoded (Example
${foo.encodeAsHTML()}).
—https://docs.grails.org/latest/guide/security.html#_double_encoding_prevention