From 76ffce6fc4627e67b59b4f5389629e5df354faa5 Mon Sep 17 00:00:00 2001 From: Jakub Kubrynski Date: Thu, 29 Jan 2015 00:20:19 +0100 Subject: [PATCH] Added regex escaping for request body matching --- .../coderate/accurest/builder/SpockMethodBodyBuilder.groovy | 4 +++- accurest-core/src/main/resources/stubs/wiremocks/sample.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/builder/SpockMethodBodyBuilder.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/builder/SpockMethodBodyBuilder.groovy index 75033ba3ff..80c38ffd36 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/builder/SpockMethodBodyBuilder.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/builder/SpockMethodBodyBuilder.groovy @@ -23,7 +23,9 @@ class SpockMethodBodyBuilder { blockBuilder.addLine(".header('$it.key', '$it.value.equalTo')") } if (stubDefinition.request.bodyPatterns) { - blockBuilder.addLine(".body('${JsonOutput.toJson(stubDefinition.request.bodyPatterns[0].matches)}')") + String matches = stubDefinition.request.bodyPatterns[0].matches + matches = matches.replaceAll('\\\\', ''); + blockBuilder.addLine(".body('${JsonOutput.toJson(matches)}')") } blockBuilder.unindent().endBlock().addEmptyLine() diff --git a/accurest-core/src/main/resources/stubs/wiremocks/sample.json b/accurest-core/src/main/resources/stubs/wiremocks/sample.json index 250e54b85a..97eaaa3cdb 100644 --- a/accurest-core/src/main/resources/stubs/wiremocks/sample.json +++ b/accurest-core/src/main/resources/stubs/wiremocks/sample.json @@ -9,7 +9,7 @@ }, "bodyPatterns": [ { - "matches": "{\"client\":{\"pesel\":\"1234567890\"},\"loanApplicationId\":123123123,\"amount\":123.123}" + "matches": "\\{\"clientPesel\":\"1234567890\",\"loanAmount\":123.123\\}" } ] },