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
19fdf2850b
commit
dc1bd8458f
@@ -456,7 +456,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,6 +26,7 @@ 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;
|
||||
@@ -81,6 +82,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