Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for GRAILS-4812

  • Loading branch information...
commit 10f681900c8f06d17d5dae99ff734fe9b827d400 1 parent f6a8586
@graemerocher graemerocher authored
View
14 grails/src/java/org/codehaus/groovy/grails/web/taglib/GroovyPageTagBody.java
@@ -16,10 +16,10 @@
import groovy.lang.Binding;
import groovy.lang.Closure;
+import groovy.lang.GString;
import org.codehaus.groovy.grails.web.pages.GroovyPage;
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest;
-import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
@@ -113,13 +113,11 @@ private Object captureClosureOutput(Object args) {
}
String output = capturedOut.getValue();
if(org.apache.commons.lang.StringUtils.isBlank(output)) {
- if(writeStringResult && (bodyResult instanceof String)) {
- try {
- originalOut.write((String)bodyResult);
- }
- catch (IOException e) {
- // ignore
- }
+ if(bodyResult instanceof String) {
+ return bodyResult;
+ }
+ else if(bodyResult instanceof GString) {
+ return bodyResult.toString();
}
else {
return BLANK_STRING;
View
36 grails/src/test/org/codehaus/groovy/grails/web/taglib/InvokeTagLibWithBodyAsMethodTests.groovy
@@ -11,6 +11,20 @@ public class InvokeTagLibWithBodyAsMethodTests extends AbstractGrailsTagTests {
public void onSetUp() {
gcl.parseClass('''
class TestTagLib {
+ def testWithClosureAndGStringReturn = { attrs, body ->
+ def foo = "bar"
+ out << "one" << test(foo:"bar") { "$foo" } << "four"
+ }
+
+ def testWithClosureAndStringReturn = { attrs, body ->
+
+ out << "one" << test(foo:"bar") { "foo" } << "four"
+ }
+
+ def testWithGStringBody = { attrs, body ->
+ def foo = "bar"
+ out << "one" << test(foo:"bar", "$foo") << "four"
+ }
def testWithStringBody = { attrs, body ->
out << "one" << test(foo:"bar", "foo") << "four"
@@ -30,6 +44,28 @@ class TestTagLib {
''')
}
+ void testWithClosureAndGStringReturn() {
+ def template = '<g:testWithClosureAndGStringReturn />'
+
+
+ assertOutputEquals 'onetwobarthreefour', template
+ }
+
+
+ void testWithClosureAndStringReturn() {
+ def template = '<g:testWithClosureAndStringReturn />'
+
+
+ assertOutputEquals 'onetwofoothreefour', template
+ }
+
+ void testInvokeTagLibAsMethodWithGString() {
+ def template = '<g:testWithGStringBody />'
+
+
+ assertOutputEquals 'onetwobarthreefour', template
+ }
+
void testInvokeTagLibAsMethodWithString() {
def template = '<g:testWithStringBody />'
Please sign in to comment.
Something went wrong with that request. Please try again.