Skip to content

Commit 7e45ece

Browse files
committed
Merge branch '2.3.x' into 2.4.x
Conflicts: grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/converters/JSONConverterTests.groovy
2 parents ca45040 + ed7bd1e commit 7e45ece

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/converters/JSONConverterTests.groovy

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import grails.persistence.Entity
77
import org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerTests
88
import org.codehaus.groovy.grails.web.servlet.mvc.HibernateProxy
99
import org.codehaus.groovy.grails.web.servlet.mvc.LazyInitializer
10+
import org.codehaus.groovy.grails.web.util.StreamCharBuffer
1011
import org.springframework.validation.BeanPropertyBindingResult
1112
import org.springframework.validation.Errors
1213

@@ -101,6 +102,25 @@ class JSONConverterTests extends AbstractGrailsControllerTests {
101102
assertEquals('{"quotedString":"I contain a \\"Quote\\"!","nonquotedString":"I don\'t!"}', json.toString())
102103
}
103104

105+
void testGStringsWithQuotes() {
106+
def json = [quotedString: "I contain a \"${'Quote'}\"!", nonquotedString: "I ${'don'}'t!"] as JSON
107+
assertEquals('{"quotedString":"I contain a \\"Quote\\"!","nonquotedString":"I don\'t!"}', json.toString())
108+
}
109+
110+
void testStreamCharBufferWithQuotes() {
111+
def quotedBuffer = new StreamCharBuffer()
112+
quotedBuffer.writer << "I contain a \"Quote\"!"
113+
def nonquotedBuffer = new StreamCharBuffer()
114+
nonquotedBuffer.writer << "I don't!"
115+
def json = [quotedString: quotedBuffer, nonquotedString: nonquotedBuffer] as JSON
116+
assertEquals('{"quotedString":"I contain a \\"Quote\\"!","nonquotedString":"I don\'t!"}', json.toString())
117+
}
118+
119+
void testObjectWithQuotes() {
120+
def json = [quotedString: new CustomCharSequence("I contain a \"Quote\"!"), nonquotedString: new CustomCharSequence("I don't!")] as JSON
121+
assertEquals('{"quotedString":"I contain a \\"Quote\\"!","nonquotedString":"I don\'t!"}', json.toString())
122+
}
123+
104124
// GRAILS-11515
105125
void testJsonMultilineSerialization() {
106126
String multiLine = "first line \n second line"
@@ -155,3 +175,31 @@ class Book {
155175
String title
156176
String author
157177
}
178+
179+
class CustomCharSequence implements CharSequence {
180+
String source
181+
182+
CustomCharSequence(String source) {
183+
this.source = source
184+
}
185+
186+
@Override
187+
public int length() {
188+
source.length()
189+
}
190+
191+
@Override
192+
public char charAt(int index) {
193+
source.charAt(index)
194+
}
195+
196+
@Override
197+
public CharSequence subSequence(int start, int end) {
198+
source.subSequence(start, end)
199+
}
200+
201+
@Override
202+
public String toString() {
203+
source
204+
}
205+
}

0 commit comments

Comments
 (0)