Discussion:
Grails 2.4.0 raw encoding broken? Plus definitely broken Test in grails-core
Otho
2014-06-01 13:04:56 UTC
Permalink
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&lt;script&gt;"
}

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?
Graeme Rocher
2014-06-01 23:20:32 UTC
Permalink
Please file a JIRA with the issues you are facing. Thanks.
Post by Otho
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
https://github.com/grails/grails-core/blob/master/grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/util/StreamCharBufferSpec.groovy
def "support raw codec"() {
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
helloEncoded.toString() == "Hello world & hi"
}
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?
--
Graeme Rocher
Grails Project Lead
SpringSource

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Loading...