Remove duplicated backslashes. Fixes gh-667

This commit is contained in:
Olga Maciaszek-Sharma
2018-10-15 16:04:53 +02:00
parent 1b36df5caf
commit 1413704cfb
2 changed files with 46 additions and 1 deletions

View File

@@ -165,7 +165,8 @@ abstract class BaseWireMockStubStrategy {
Map convertedMap = MapConverter.transformValues(value) {
it instanceof GString ? it.toString() : it
} as Map
return new JSONObject(new JsonBuilder(convertedMap).toString())
String jsonOutput = new JSONObject(new JsonBuilder(convertedMap).toString()).toString()
return jsonOutput.replaceAll("\\\\\\\\\\\\", "\\\\")
}
return new JsonBuilder(value).toString()
}

View File

@@ -2154,6 +2154,50 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
@Issue('#667')
def "should not double escape backslashes"() {
given:
Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make {
priority 1
request {
method 'GET'
urlPath(value(consumer(regex(/\/data\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)),
producer('/data/444d57b2-e309-4576-83cb-5530ee03106a')))
}
response {
status 200
headers {
header("Content-Type", "application/json;charset=UTF-8")
}
body([
jsonString: '{\\"attribute\\": \\"value\\"}'
])
}
}
when:
String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null, groovyDsl), groovyDsl).toWireMockClientStub()
then:
AssertionUtil.assertThatJsonsAreEqual('''
{
"request" : {
"urlPathPattern" : "/data/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\\"jsonString\\":\\"{\\\\\\"attribute\\\\\\": \\\\\\"value\\\\\\"}\\"}",
"headers" : {
"Content-Type" : "application/json;charset=UTF-8"
},
"transformers" : [ "response-template", "foo-transformer" ]
},
"priority" : 1
}
''', wireMockStub)
and:
stubMappingIsValidWireMockStub(wireMockStub)
}
WireMockConfiguration config() {
return new WireMockConfiguration().extensions(responseTemplateTransformer())
}