Otho
2014-06-01 13:04:56 UTC
At the moment I am trying to display highlighted search results. The
highlight tags are <span class="highlight">...</span>. Regardless how I
proceed with the encodings it is always displayed escaped.
In the controller: def displayField = result.someProperty.encodeAsRaw() has
no effect, in the gsp neither ${raw(someValue)} nor
${someValue.encodeAsRaw()} nor the <g:encodeAs
codec="raw">someValue</g:encodeAs> work.
I didn't get to the root of it all yet, but while searching the net for
related issues I stumbled over the following unit test:
https://github.com/grails/grails-core/blob/master/grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/util/StreamCharBufferSpec.groovy
Excerpt (bold by me):
def "support raw codec"() {
when:
def hello="Hello world & hi"
*def buffer2*=new StreamCharBuffer()
def writer = new GrailsPrintWriter(buffer2.writerForEncoder)
writer << hello
writer.flush()
* def buffer3*=new StreamCharBuffer()
def helloEncoded = buffer2.encodeAsRaw().encodeAsHTML()
def writer2 = new GrailsPrintWriter(buffer3.writerForEncoder)
writer2 << helloEncoded
writer2 << "<script>"
codecOut << buffer3
then:
helloEncoded.toString() == "Hello world & hi"
*buffer*.toString() == "Hello world & hi<script>"
}
Seems to be a copy/paste mistake. buffer2 and buffer3 are used, but buffer
is tested in the then: clause. buffer is defined in the setup, but not
manipulated here, so the test always tests against the last valid spec.
Maybe there the possible bugs with raw encoding could stay undetected?
highlight tags are <span class="highlight">...</span>. Regardless how I
proceed with the encodings it is always displayed escaped.
In the controller: def displayField = result.someProperty.encodeAsRaw() has
no effect, in the gsp neither ${raw(someValue)} nor
${someValue.encodeAsRaw()} nor the <g:encodeAs
codec="raw">someValue</g:encodeAs> work.
I didn't get to the root of it all yet, but while searching the net for
related issues I stumbled over the following unit test:
https://github.com/grails/grails-core/blob/master/grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/util/StreamCharBufferSpec.groovy
Excerpt (bold by me):
def "support raw codec"() {
when:
def hello="Hello world & hi"
*def buffer2*=new StreamCharBuffer()
def writer = new GrailsPrintWriter(buffer2.writerForEncoder)
writer << hello
writer.flush()
* def buffer3*=new StreamCharBuffer()
def helloEncoded = buffer2.encodeAsRaw().encodeAsHTML()
def writer2 = new GrailsPrintWriter(buffer3.writerForEncoder)
writer2 << helloEncoded
writer2 << "<script>"
codecOut << buffer3
then:
helloEncoded.toString() == "Hello world & hi"
*buffer*.toString() == "Hello world & hi<script>"
}
Seems to be a copy/paste mistake. buffer2 and buffer3 are used, but buffer
is tested in the then: clause. buffer is defined in the setup, but not
manipulated here, so the test always tests against the last valid spec.
Maybe there the possible bugs with raw encoding could stay undetected?