Escapes any special chars; fixes gh-1635
This commit is contained in:
@@ -36,7 +36,7 @@ abstract class PatternValueDslProperty<T extends DslProperty> implements RegexCr
|
||||
boolean matches = pattern.matcher(generatedValue).matches();
|
||||
if (!matches) {
|
||||
throw new IllegalStateException("The generated value [" + generatedValue
|
||||
+ "] doesn\'t match the pattern [" + pattern.pattern() + "]");
|
||||
+ "] doesn't match the pattern [" + pattern.pattern() + "]");
|
||||
}
|
||||
|
||||
return createProperty(pattern, object);
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.stream.Collectors;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.cloud.contract.spec.util.RegexpUtils;
|
||||
|
||||
/**
|
||||
* Contains most common regular expression patterns.
|
||||
*
|
||||
@@ -87,7 +89,7 @@ public final class RegexPatterns {
|
||||
"([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\.\\d+)?(Z|[+-][01]\\d:[0-5]\\d)");
|
||||
|
||||
protected static Pattern anyOf(String... values) {
|
||||
return Pattern.compile(Arrays.stream(values).map(it -> '^' + it + '$').collect(Collectors.joining("|")));
|
||||
return Pattern.compile(Arrays.stream(values).map(it -> '^' + RegexpUtils.escapeSpecialRegexWithSingleEscape(it) + '$').collect(Collectors.joining("|")));
|
||||
}
|
||||
|
||||
public static String multipartParam(Object name, Object value) {
|
||||
|
||||
Reference in New Issue
Block a user