Merge branch '2.0.x'
This commit is contained in:
@@ -22,8 +22,7 @@ import java.util.regex.Pattern;
|
||||
import com.toomuchcoding.jsonassert.JsonVerifiable;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import static org.apache.commons.text.StringEscapeUtils.escapeJava;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link MethodBufferingJsonVerifiable} that contains a list
|
||||
@@ -163,12 +162,12 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable {
|
||||
DelegatingJsonVerifiable readyToCheck = new FinishedDelegatingJsonVerifiable(this.delegate.jsonPath(),
|
||||
this.delegate.isEqualTo(value), this.methodsBuffer, value);
|
||||
if (this.delegate.isAssertingAValueInArray() && readyToCheck.methodsBuffer.peekLast().equals(".arrayField()")) {
|
||||
readyToCheck.appendMethodWithQuotedValue("isEqualTo", escapeJava(value));
|
||||
readyToCheck.appendMethodWithQuotedValue("isEqualTo", escapedHackedJavaText(value));
|
||||
readyToCheck.methodsBuffer.offer(".value()");
|
||||
} else if (this.delegate.isAssertingAValueInArray() && !readyToCheck.methodsBuffer.peekLast().contains("array")) {
|
||||
readyToCheck.methodsBuffer.offer(".value()");
|
||||
} else {
|
||||
readyToCheck.appendMethodWithQuotedValue("isEqualTo", escapeJava(value));
|
||||
readyToCheck.appendMethodWithQuotedValue("isEqualTo", escapedHackedJavaText(value));
|
||||
}
|
||||
return readyToCheck;
|
||||
}
|
||||
@@ -253,7 +252,7 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable {
|
||||
* an double escaped text. Related to https://github.com/spring-cloud/spring-cloud-contract/issues/169
|
||||
*/
|
||||
private String escapedHackedJavaText(String value) {
|
||||
return escapeJava(value)
|
||||
return StringEscapeUtils.escapeJava(value)
|
||||
.replace("\\\"", "\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -1039,4 +1039,44 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue("#852")
|
||||
def "should work with escaped quotes [#methodBuilderName]"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
url('/test')
|
||||
headers {
|
||||
accept(applicationJson())
|
||||
header("X-Authorization", "eyJhbGciOiJIUzI1NiJ9.eyJtZW1iZXJObyI6IjEyMzQ1In0.VdYumw6QkfxaBgFUZNyza1VfNKiZ2WW4JaxIKe-G8HA")
|
||||
}
|
||||
}
|
||||
response {
|
||||
status OK()
|
||||
body([
|
||||
"test": "\"escaped\""
|
||||
])
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
String test = blockBuilder.toString()
|
||||
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test)
|
||||
!test.contains('''.isEqualTo("\\\\"escaped\\\\"")''')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user