Fixed the invalid regex escape

fixes #162
This commit is contained in:
Marcin Grzejszczak
2016-12-07 16:29:11 +01:00
parent 545874c951
commit c067774eee
9 changed files with 84 additions and 6 deletions

View File

@@ -20,6 +20,8 @@ import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import groovy.transform.TypeChecked
import java.util.regex.Pattern
/**
* Represents a set of headers of a request / response or a message
*
@@ -68,6 +70,10 @@ class Headers {
return new DslProperty(value)
}
protected NotToEscapePattern notEscaped(Pattern pattern) {
return new NotToEscapePattern(pattern)
}
/**
* Converts the headers into their stub side representations and returns as
* a map of String key => Object value.

View File

@@ -0,0 +1,21 @@
package org.springframework.cloud.contract.spec.internal
import java.util.regex.Pattern
/**
* Special case of Patterns that we don't want to escape
*
* @author Marcin Grzejszczak
* @since 1.0.3
*/
class NotToEscapePattern extends DslProperty<Pattern> {
NotToEscapePattern(Pattern clientValue, Pattern serverValue) {
super(clientValue, serverValue)
}
NotToEscapePattern(Pattern singleValue) {
super(singleValue)
}
}

View File

@@ -144,7 +144,7 @@ class Response extends Common {
@Override
DslProperty matching(String value) {
return $(p(Pattern.compile("${RegexpUtils.escapeSpecialRegexWithSingleEscape(value)}.*")),
return $(p(notEscaped(Pattern.compile("${RegexpUtils.escapeSpecialRegexWithSingleEscape(value)}.*"))),
c(value))
}
}