Fix encoding issue
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package io.codearte.accurest.builder
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.StringEscapeUtils
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
@@ -117,7 +119,13 @@ abstract class SpockMethodBodyBuilder {
|
||||
|
||||
protected String getBodyAsString() {
|
||||
Object bodyValue = extractServerValueFromBody(request.body.serverValue)
|
||||
return trimRepeatedQuotes(new JsonOutput().toJson(bodyValue))
|
||||
String json = new JsonOutput().toJson(bodyValue)
|
||||
json = convertUnicodeEscapes(json)
|
||||
return trimRepeatedQuotes(json)
|
||||
}
|
||||
|
||||
protected String convertUnicodeEscapes(String json) {
|
||||
return StringEscapeUtils.unescapeJavaScript(json)
|
||||
}
|
||||
|
||||
protected String trimRepeatedQuotes(String toTrim) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import spock.lang.Issue
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Unroll
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* @author Jakub Kubrynski
|
||||
*/
|
||||
@@ -669,4 +671,39 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
then:
|
||||
spockTest.contains('''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))''')
|
||||
}
|
||||
|
||||
def "shouldn't generate unicode escape characters"() {
|
||||
given:
|
||||
Pattern ONLY_ALPHA_UNICODE = Pattern.compile(/[\p{L}]*/)
|
||||
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "PUT"
|
||||
url "/v1/payments/e86df6f693de4b35ae648464c5b0dc09/енев"
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
}
|
||||
body(
|
||||
client: [
|
||||
first_name: $(stub(ONLY_ALPHA_UNICODE), test('Пенева')),
|
||||
last_name : $(stub(ONLY_ALPHA_UNICODE), test('Пенева'))
|
||||
]
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
then:
|
||||
!spockTest.contains("\\u041f")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user