Skip to content

Commit 3872b37

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: #3635 Original pull request: #3637.
1 parent 98fe043 commit 3872b37

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,6 @@ private Object applyFieldTargetTypeHintToValue(Field documentField, @Nullable Ob
797797
*/
798798
static class Keyword {
799799

800-
private static final String N_OR_PATTERN = "\\$.*or";
801800
private static final Set<String> NON_DBREF_CONVERTING_KEYWORDS = new HashSet<>(
802801
Arrays.asList("$", "$size", "$slice", "$gt", "$lt"));
803802

@@ -828,7 +827,7 @@ public boolean isExists() {
828827
}
829828

830829
public boolean isOrOrNor() {
831-
return key.matches(N_OR_PATTERN);
830+
return key.equalsIgnoreCase("$or") || key.equalsIgnoreCase("$nor");
832831
}
833832

834833
/**

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,14 @@ void mapsNullBsonTypeForFieldWithCustomTargetType() {
12771277
assertThat(document).isEqualTo(new org.bson.Document("stringAsOid", new org.bson.Document("$type", 10)));
12781278
}
12791279

1280+
@Test // GH-3635
1281+
void $floorKeywordDoesNotMatch$or$norPattern() {
1282+
1283+
Query query = new BasicQuery(" { $expr: { $gt: [ \"$spent\" , { $floor : \"$budget\" } ] } }");
1284+
assertThatNoException()
1285+
.isThrownBy(() -> mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class)));
1286+
}
1287+
12801288
class WithDeepArrayNesting {
12811289

12821290
List<WithNestedArray> level0;

0 commit comments

Comments
 (0)