Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3871-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3871-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3871-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3871-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static java.util.Arrays.*;
import static org.bson.assertions.Assertions.*;
import static org.bson.codecs.configuration.CodecRegistries.*;
import static org.springframework.data.mongodb.util.json.ParameterBindingJsonReader.*;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -217,6 +218,9 @@ public Document decode(final BsonReader reader, final DecoderContext decoderCont
if (bindingReader.currentValue instanceof org.bson.Document) {
return (Document) bindingReader.currentValue;
}
if(ObjectUtils.nullSafeEquals(bindingReader.currentValue, PLACEHOLDER)) {
return new Document();
}
}

Document document = new Document();
Expand Down Expand Up @@ -377,8 +381,6 @@ private List<Object> readList(final BsonReader reader, final DecoderContext deco
*/
static class DependencyCapturingExpressionEvaluator implements SpELExpressionEvaluator {

private static final Object PLACEHOLDER = new Object();

private final ExpressionParser expressionParser;
private final List<ExpressionDependencies> dependencies = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
*/
public class ParameterBindingJsonReader extends AbstractBsonReader {

static final Object PLACEHOLDER = new Object();

private static final Pattern PARAMETER_ONLY_BINDING_PATTERN = Pattern.compile("^\\?(\\d+)$");
private static final Pattern EXPRESSION_ONLY_BINDING_PATTERN = Pattern.compile("^\\?#\\{.*\\}$");
private static final Pattern PARAMETER_BINDING_PATTERN = Pattern.compile("\\?(\\d+)");
private static final Pattern EXPRESSION_BINDING_PATTERN = Pattern.compile("[\\?:]#\\{.*\\}");

Expand Down Expand Up @@ -110,11 +113,7 @@ public ParameterBindingJsonReader(String json, ValueProvider accessor, SpelExpre
setContext(new Context(null, BsonContextType.TOP_LEVEL));

this.bindingContext = new ParameterBindingContext(accessor, spelExpressionParser, evaluationContext);

Matcher matcher = PARAMETER_ONLY_BINDING_PATTERN.matcher(json);
if (matcher.find()) {
currentValue = bindableValueFor(new JsonToken(JsonTokenType.UNQUOTED_STRING, json)).getValue();
}
setInitialValueIfFullDocumentExpression(json);
}

public ParameterBindingJsonReader(String json, ParameterBindingContext bindingContext) {
Expand All @@ -123,9 +122,13 @@ public ParameterBindingJsonReader(String json, ParameterBindingContext bindingCo
setContext(new Context(null, BsonContextType.TOP_LEVEL));

this.bindingContext = bindingContext;
setInitialValueIfFullDocumentExpression(json);
}

Matcher matcher = PARAMETER_ONLY_BINDING_PATTERN.matcher(json);
if (matcher.find()) {
public void setInitialValueIfFullDocumentExpression(String json) {
if (PARAMETER_ONLY_BINDING_PATTERN.matcher(json).find()) {
currentValue = bindableValueFor(new JsonToken(JsonTokenType.UNQUOTED_STRING, json)).getValue();
} else if (EXPRESSION_ONLY_BINDING_PATTERN.matcher(json).find()) {
currentValue = bindableValueFor(new JsonToken(JsonTokenType.UNQUOTED_STRING, json)).getValue();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ void evaluatesSpelExpressionDefiningEntireQuery() {
new Document("user.supervisor", "wonderwoman"))));
}

@Test // GH-3871
public void capturingExpressionDependenciesShouldNotThrowParseErrorForSpelOnlyJson() {

Object[] args = new Object[] { "1", "2" };
String json = "?#{ true ? { 'name': #name } : { 'name' : #name + 'trouble' } }";

new ParameterBindingDocumentCodec().captureExpressionDependencies(json, (index) -> args[index], new SpelExpressionParser());
}

@Test // DATAMONGO-2571
void shouldParseRegexCorrectly() {

Expand Down