Skip to content

Commit 5d8f3d5

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 5cf801f commit 5d8f3d5

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
@@ -721,7 +721,6 @@ private Object applyFieldTargetTypeHintToValue(Field documentField, @Nullable Ob
721721
*/
722722
static class Keyword {
723723

724-
private static final String N_OR_PATTERN = "\\$.*or";
725724
private static final Set<String> NON_DBREF_CONVERTING_KEYWORDS = new HashSet<>(
726725
Arrays.asList("$", "$size", "$slice", "$gt", "$lt"));
727726

@@ -752,7 +751,7 @@ public boolean isExists() {
752751
}
753752

754753
public boolean isOrOrNor() {
755-
return key.matches(N_OR_PATTERN);
754+
return key.equalsIgnoreCase("$or") || key.equalsIgnoreCase("$nor");
756755
}
757756

758757
/**

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

+8
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,14 @@ void mapsNullValueForFieldWithCustomTargetType() {
10931093
assertThat(document).isEqualTo(new org.bson.Document("stringAsOid", null));
10941094
}
10951095

1096+
@Test // GH-3635
1097+
void $floorKeywordDoesNotMatch$or$norPattern() {
1098+
1099+
Query query = new BasicQuery(" { $expr: { $gt: [ \"$spent\" , { $floor : \"$budget\" } ] } }");
1100+
assertThatNoException()
1101+
.isThrownBy(() -> mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class)));
1102+
}
1103+
10961104
class WithDeepArrayNesting {
10971105

10981106
List<WithNestedArray> level0;

0 commit comments

Comments
 (0)