Skip to content

Commit d33aa68

Browse files
christophstroblmp911de
authored andcommitted
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: spring-projects#3635 Original pull request: spring-projects#3637.
1 parent f6db089 commit d33aa68

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
@@ -792,7 +792,6 @@ private Object applyFieldTargetTypeHintToValue(Field documentField, @Nullable Ob
792792
*/
793793
static class Keyword {
794794

795-
private static final String N_OR_PATTERN = "\\$.*or";
796795
private static final Set<String> NON_DBREF_CONVERTING_KEYWORDS = new HashSet<>(
797796
Arrays.asList("$", "$size", "$slice", "$gt", "$lt"));
798797

@@ -823,7 +822,7 @@ public boolean isExists() {
823822
}
824823

825824
public boolean isOrOrNor() {
826-
return key.matches(N_OR_PATTERN);
825+
return key.equalsIgnoreCase("$or") || key.equalsIgnoreCase("$nor");
827826
}
828827

829828
/**

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

+8
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,14 @@ void mapsNullValueForFieldWithCustomTargetType() {
12681268
assertThat(document).isEqualTo(new org.bson.Document("stringAsOid", null));
12691269
}
12701270

1271+
@Test // GH-3635
1272+
void $floorKeywordDoesNotMatch$or$norPattern() {
1273+
1274+
Query query = new BasicQuery(" { $expr: { $gt: [ \"$spent\" , { $floor : \"$budget\" } ] } }");
1275+
assertThatNoException()
1276+
.isThrownBy(() -> mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class)));
1277+
}
1278+
12711279
class WithDeepArrayNesting {
12721280

12731281
List<WithNestedArray> level0;

0 commit comments

Comments
 (0)