Skip to content

Commit

Permalink
fix for GRAILS-4812
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Jul 20, 2009
1 parent f6a8586 commit 10f6819
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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"
Expand All @@ -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 />'
Expand Down

0 comments on commit 10f6819

Please sign in to comment.