DATAMONGO-2476 - Fix Json parsing for unquoted placeholders in arrays.
Original pull request: #835.
This commit is contained in:
committed by
Mark Paluch
parent
22ca597fca
commit
81c68955fe
@@ -219,7 +219,7 @@ class JsonScanner {
|
||||
boolean isExpression = false;
|
||||
int parenthesisCount = 0;
|
||||
|
||||
while (c == '$' || c == '_' || Character.isLetterOrDigit(c) || c == '#' || c == '{' || c == '[' || c == ']'
|
||||
while (c == '$' || c == '_' || Character.isLetterOrDigit(c) || c == '#' || c == '{' || c == '['
|
||||
|| (isExpression && isExpressionAllowedChar(c))) {
|
||||
|
||||
if (charCount == 0 && c == '#') {
|
||||
|
||||
@@ -220,6 +220,41 @@ public class ParameterBindingJsonReaderUnitTests {
|
||||
assertThat(target).isEqualTo(new Document("name", "value"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindUnquotedParameterInArray() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : [?0] } }", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in", Collections.singletonList("kohlin"))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindMultipleUnquotedParameterInArray() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : [?0,?1] } }", "dalinar", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in",Arrays.asList("dalinar", "kohlin"))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindUnquotedParameterInArrayWithSpaces() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : [ ?0 ] } }", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in", Collections.singletonList("kohlin"))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindQuotedParameterInArray() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : ['?0'] } }", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in", Collections.singletonList("kohlin"))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindQuotedMulitParameterInArray() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : ['?0,?1'] } }", "dalinar", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in", Collections.singletonList("dalinar,kohlin"))));
|
||||
}
|
||||
|
||||
private static Document parse(String json, Object... args) {
|
||||
|
||||
ParameterBindingJsonReader reader = new ParameterBindingJsonReader(json, args);
|
||||
|
||||
Reference in New Issue
Block a user