Retain regex options from the parsed JsonToken.
We now retain expression options when resolving bind values from the original BsonRegularExpression. Closes: #4806 Original Pull Request: #4807
This commit is contained in:
committed by
Christoph Strobl
parent
6e850512c0
commit
60a3461bb1
@@ -461,7 +461,9 @@ public class ParameterBindingJsonReader extends AbstractBsonReader {
|
||||
|
||||
if (isRegularExpression) {
|
||||
|
||||
bindableValue.setValue(new BsonRegularExpression(computedValue));
|
||||
BsonRegularExpression originalExpression = token.getValue(BsonRegularExpression.class);
|
||||
|
||||
bindableValue.setValue(new BsonRegularExpression(computedValue, originalExpression.getOptions()));
|
||||
bindableValue.setType(BsonType.REGULAR_EXPRESSION);
|
||||
} else {
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ import java.util.UUID;
|
||||
|
||||
import org.bson.BsonBinary;
|
||||
import org.bson.BsonBinarySubType;
|
||||
import org.bson.BsonRegularExpression;
|
||||
import org.bson.Document;
|
||||
import org.bson.codecs.DecoderContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.expression.ValueExpressionParser;
|
||||
import org.springframework.data.mapping.model.ValueExpressionEvaluator;
|
||||
import org.springframework.data.spel.EvaluationContextProvider;
|
||||
import org.springframework.data.spel.ExpressionDependencies;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
@@ -84,6 +84,26 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
assertThat(target).isEqualTo(new Document("lastname", "100"));
|
||||
}
|
||||
|
||||
@Test // GH-4806
|
||||
void regexConsidersOptions() {
|
||||
|
||||
Document target = parse("{ 'c': /^true$/i }");
|
||||
|
||||
BsonRegularExpression pattern = target.get("c", BsonRegularExpression.class);
|
||||
assertThat(pattern.getPattern()).isEqualTo("^true$");
|
||||
assertThat(pattern.getOptions()).isEqualTo("i");
|
||||
}
|
||||
|
||||
@Test // GH-4806
|
||||
void regexConsidersBindValueWithOptions() {
|
||||
|
||||
Document target = parse("{ 'c': /^?0$/i }", "foo");
|
||||
|
||||
BsonRegularExpression pattern = target.get("c", BsonRegularExpression.class);
|
||||
assertThat(pattern.getPattern()).isEqualTo("^foo$");
|
||||
assertThat(pattern.getOptions()).isEqualTo("i");
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindValueToRegex() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user