Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: grails/grails-core
base: 6fb016dab6
...
head fork: grails/grails-core
compare: 23b81684e5
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
62 ...-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/util/CodecPrintWriterTest.java
@@ -14,10 +14,16 @@
import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.commons.GrailsClass;
import org.codehaus.groovy.grails.plugins.codecs.HTMLCodec;
+import org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpServletRequest;
+import org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpServletResponse;
import org.codehaus.groovy.grails.web.pages.FastStringWriter;
+import org.codehaus.groovy.grails.web.pages.GroovyPageOutputStack;
+import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes;
+import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
+import org.springframework.web.context.request.RequestContextHolder;
public class CodecPrintWriterTest {
@@ -56,6 +62,62 @@ public void testPrintStreamCharBufferWithClosure() throws IOException {
writer.write(buf);
assertEquals("-> hola <-", stringwriter.getValue());
}
+
+ @Test
+ public void testCodecAndNoCodecGRAILS8405() throws IOException {
+ FastStringWriter target=new FastStringWriter();
+
+ GrailsWebRequest webRequest = bindMockHttpRequest();
+
+ // Initialize out and codecOut as it is done in GroovyPage.initRun
+ GroovyPageOutputStack outputStack = GroovyPageOutputStack.currentStack(true, target, false, true);
+ GrailsPrintWriter out = outputStack.getProxyWriter();
+ webRequest.setOut(out);
+ GrailsPrintWriter codecOut=new CodecPrintWriter(new MockGrailsApplication(), out, CodecWithClosureProperties.class);
+
+ // print some output
+ codecOut.print("hola");
+ out.print("1");
+ out.print("2");
+ out.print("3");
+
+ // similar as taglib call
+ FastStringWriter bufferWriter=new FastStringWriter();
+ GrailsPrintWriter out2=new GrailsPrintWriter(bufferWriter);
+ outputStack.push(out2);
+ out.print("4");
+ codecOut.print("A");
+ outputStack.pop();
+
+ // add output before appending "taglib output"
+ out.print("added");
+ codecOut.print("too");
+
+ // append "taglib output"
+ out.leftShift(bufferWriter.getBuffer());
+
+ // print some more output
+ codecOut.print("B");
+ out.print("5");
+ codecOut.print("C");
+
+ // clear thread local
+ RequestContextHolder.setRequestAttributes(null);
+
+ assertEquals("-> hola <-123added-> too <-4-> A <--> B <-5-> C <-", target.getValue());
+ }
+
+ private GrailsWebRequest bindMockHttpRequest() {
+ GrailsMockHttpServletRequest mockRequest=new GrailsMockHttpServletRequest();
+ GrailsMockHttpServletResponse mockResponse=new GrailsMockHttpServletResponse();
+ GrailsWebRequest webRequest = new GrailsWebRequest(mockRequest, mockResponse, mockRequest.getServletContext());
+ mockRequest.setAttribute(GrailsApplicationAttributes.WEB_REQUEST, webRequest);
+ RequestContextHolder.setRequestAttributes(webRequest);
+ return webRequest;
+ }
+
+
+
}
@SuppressWarnings({ "rawtypes", "unchecked" })
View
9 grails-web/src/main/groovy/org/codehaus/groovy/grails/web/pages/GroovyPage.java
@@ -120,12 +120,21 @@
@SuppressWarnings("rawtypes")
public static final class ConstantClosure extends Closure {
private static final long serialVersionUID = 1L;
+ private static final Class[] EMPTY_CLASS_ARR=new Class[0];
final Object retval;
public ConstantClosure(Object retval) {
super(null);
this.retval = retval;
}
+
+ public int getMaximumNumberOfParameters() {
+ return 0;
+ }
+
+ public Class[] getParameterTypes() {
+ return EMPTY_CLASS_ARR;
+ }
public Object doCall(@SuppressWarnings("unused") Object obj) {
return retval;
View
144 grails-web/src/main/groovy/org/codehaus/groovy/grails/web/util/CodecPrintWriter.java
@@ -8,6 +8,7 @@
import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.commons.GrailsCodecClass;
+import org.codehaus.groovy.runtime.GStringImpl;
public class CodecPrintWriter extends GrailsPrintWriter {
private Closure<?> encodeClosure;
@@ -18,7 +19,22 @@ public CodecPrintWriter(GrailsApplication grailsApplication, Writer out, Class<?
initEncode(grailsApplication,codecClass);
}
-
+
+ @Override
+ public void setOut(Writer newOut) {
+ this.out = newOut;
+ }
+
+ @Override
+ public boolean isUsed() {
+ return usageFlag;
+ }
+
+ @Override
+ protected Writer findStreamCharBufferTarget(boolean markUsed) {
+ return unwrapWriter(getOut());
+ }
+
private void initEncode(GrailsApplication grailsApplication, Class<?> codecClass) {
if (grailsApplication != null && codecClass != null) {
GrailsCodecClass codecArtefact = (GrailsCodecClass) grailsApplication.getArtefact("Codec", codecClass.getName());
@@ -50,7 +66,7 @@ private Object encodeObject(Object o) {
public void print(final Object obj) {
encodeAndPrint(obj);
}
-
+
private void encodeAndPrint(final Object obj) {
if (trouble || obj == null) {
usageFlag = true;
@@ -63,8 +79,9 @@ private void encodeAndPrint(final Object obj) {
super.write((String)encoded);
} else if (clazz == StreamCharBuffer.class) {
super.write((StreamCharBuffer)encoded);
- }
- else if (encoded instanceof Writable) {
+ } else if (clazz == GStringImpl.class) {
+ super.write((Writable)encoded);
+ } else if (encoded instanceof Writable) {
super.write((Writable)encoded);
}
else if (obj instanceof CharSequence) {
@@ -142,114 +159,6 @@ public void write(final char buf[]) {
encodeAndPrint(new String(buf));
}
- /** delegate methods, not synchronized **/
-
- @Override
- public void print(final boolean b) {
- if (b) {
- write("true");
- }
- else {
- write("false");
- }
- }
-
- @Override
- public void print(final char c) {
- write(c);
- }
-
- @Override
- public void print(final int i) {
- write(String.valueOf(i));
- }
-
- @Override
- public void print(final long l) {
- write(String.valueOf(l));
- }
-
- @Override
- public void print(final float f) {
- write(String.valueOf(f));
- }
-
- @Override
- public void print(final double d) {
- write(String.valueOf(d));
- }
-
- @Override
- public void print(final char s[]) {
- write(s);
- }
-
- @Override
- public void println() {
- usageFlag = true;
- write(CRLF);
- }
-
- @Override
- public void println(final boolean b) {
- print(b);
- println();
- }
-
- @Override
- public void println(final char c) {
- print(c);
- println();
- }
-
- @Override
- public void println(final int i) {
- print(i);
- println();
- }
-
- @Override
- public void println(final long l) {
- print(l);
- println();
- }
-
- @Override
- public void println(final float f) {
- print(f);
- println();
- }
-
- @Override
- public void println(final double d) {
- print(d);
- println();
- }
-
- @Override
- public void println(final char c[]) {
- print(c);
- println();
- }
-
- @Override
- public void println(final String s) {
- print(s);
- println();
- }
-
- @Override
- public void println(final Object o) {
- print(o);
- println();
- }
-
- @Override
- public GrailsPrintWriter append(final char c) {
- write(c);
- return this;
- }
-
@Override
public GrailsPrintWriter append(final CharSequence csq, final int start, final int end) {
encodeAndPrint(csq.subSequence(start, end));
@@ -314,15 +223,4 @@ public void write(final Writable writable) {
handleIOException(e);
}
}
-
- @Override
- public void print(final Writable writable) {
- write(writable);
- }
-
- @Override
- public GrailsPrintWriter leftShift(final Writable writable) {
- write(writable);
- return this;
- }
}
View
28 grails-web/src/main/groovy/org/codehaus/groovy/grails/web/util/GrailsPrintWriter.java
@@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.grails.web.util;
+import groovy.lang.GString;
import groovy.lang.Writable;
import java.io.IOException;
@@ -24,6 +25,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.groovy.grails.web.util.StreamCharBuffer.StreamCharBufferWriter;
+import org.codehaus.groovy.runtime.GStringImpl;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
@@ -44,7 +46,7 @@
protected Writer previousOut = null;
public GrailsPrintWriter(Writer out) {
- this.out = out;
+ setOut(out);
}
public boolean isAllowUnwrappingOut() {
@@ -63,10 +65,16 @@ public Writer getOut() {
}
public void setOut(Writer newOut) {
- if(newOut instanceof GrailsWrappedWriter ) {
- this.out = ((GrailsWrappedWriter)newOut).unwrap();
+ this.out = unwrapWriter(newOut);
+ this.streamCharBufferTarget = null;
+ this.previousOut = null;
+ }
+
+ protected Writer unwrapWriter(Writer writer) {
+ if(writer instanceof GrailsWrappedWriter ) {
+ return ((GrailsWrappedWriter)writer).unwrap();
} else {
- this.out = newOut;
+ return writer;
}
}
@@ -167,6 +175,9 @@ public void print(final Object obj) {
else if (clazz == StreamCharBuffer.class) {
write((StreamCharBuffer)obj);
}
+ else if (clazz == GStringImpl.class) {
+ write((Writable)obj);
+ }
else if (obj instanceof Writable) {
write((Writable)obj);
}
@@ -512,6 +523,15 @@ public GrailsPrintWriter leftShift(final Writable writable) {
return this;
}
+ public void print(final GStringImpl gstring) {
+ write((Writable)gstring);
+ }
+
+ public GrailsPrintWriter leftShift(final GStringImpl gstring) {
+ write((Writable)gstring);
+ return this;
+ }
+
public boolean isUsed() {
if (usageFlag) {
return true;

No commit comments for this range

Something went wrong with that request. Please try again.