Skip to content

Commit c57c62a

Browse files
Fix $or / $nor keyword mapping in query mapper.
This commit fixes an issue with the pattern used for detecting $or / $nor which also matched other keywords like $floor. Closes: #3635
1 parent 9b8cd8e commit c57c62a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ private Object applyFieldTargetTypeHintToValue(Field documentField, Object value
787787
*/
788788
static class Keyword {
789789

790-
private static final String N_OR_PATTERN = "\\$.*or";
791790
private static final Set<String> NON_DBREF_CONVERTING_KEYWORDS = new HashSet<>(
792791
Arrays.asList("$", "$size", "$slice", "$gt", "$lt"));
793792

@@ -818,7 +817,7 @@ public boolean isExists() {
818817
}
819818

820819
public boolean isOrOrNor() {
821-
return key.matches(N_OR_PATTERN);
820+
return key.equalsIgnoreCase("$or") || key.equalsIgnoreCase("$nor");
822821
}
823822

824823
/**

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,14 @@ void resolvesFieldNameWithUnderscoreOnNestedMappedFieldnameWithUnderscoresCorrec
12571257
assertThat(document).isEqualTo(new org.bson.Document("double_underscore.renamed", new org.bson.Document("$exists", true)));
12581258
}
12591259

1260+
@Test // GH-3635
1261+
void $floorKeywordDoesNotMatch$or$norPattern() {
1262+
1263+
Query query = new BasicQuery(" { $expr: { $gt: [ \"$spent\" , { $floor : \"$budget\" } ] } }");
1264+
assertThatNoException()
1265+
.isThrownBy(() -> mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class)));
1266+
}
1267+
12601268
class WithDeepArrayNesting {
12611269

12621270
List<WithNestedArray> level0;

0 commit comments

Comments
 (0)