Fix QueryMapper property path resolution for nested paths containing numeric values.
Prior to this fix a path that contains numeric values used as position parameters would have been stripped in a way that left out the last digit. This could lead to wrong path resolution if the incorrectly constructed property name accidentally matched an existing one. Closes: #4426 Original Pull Request: #4427
This commit is contained in:
committed by
Christoph Strobl
parent
56e763c9c0
commit
0cd082e7fa
@@ -1233,6 +1233,18 @@ public class QueryMapper {
|
|||||||
|
|
||||||
String rawPath = removePlaceholders(POSITIONAL_OPERATOR,
|
String rawPath = removePlaceholders(POSITIONAL_OPERATOR,
|
||||||
removePlaceholders(DOT_POSITIONAL_PATTERN, pathExpression));
|
removePlaceholders(DOT_POSITIONAL_PATTERN, pathExpression));
|
||||||
|
// fix xx.11.22.33 becomes xx3, it should be xx.33, then path should be null. (test mapNestedLastBigIntegerFieldCorrectly)
|
||||||
|
if (pathExpression.contains(".")) {
|
||||||
|
String lastDotString = pathExpression.substring(pathExpression.lastIndexOf("."));
|
||||||
|
int lastDotLength = lastDotString.length();
|
||||||
|
int newLength = 0;
|
||||||
|
if (rawPath.contains(".")) {
|
||||||
|
newLength = rawPath.substring(rawPath.lastIndexOf(".")).length();
|
||||||
|
}
|
||||||
|
if (lastDotLength != newLength) {
|
||||||
|
rawPath = rawPath.substring(0, rawPath.length() - 1) + lastDotString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sourceProperty != null && sourceProperty.getOwner().equals(entity)) {
|
if (sourceProperty != null && sourceProperty.getOwner().equals(entity)) {
|
||||||
return mappingContext.getPersistentPropertyPath(
|
return mappingContext.getPersistentPropertyPath(
|
||||||
|
|||||||
@@ -1223,6 +1223,16 @@ class UpdateMapperUnitTests {
|
|||||||
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.3", "4")));
|
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.3", "4")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mapNestedLastBigIntegerFieldCorrectly() {
|
||||||
|
|
||||||
|
Update update = new Update().set("levelOne.0.1.32", "4");
|
||||||
|
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
|
||||||
|
context.getPersistentEntity(EntityWithNestedMap.class));
|
||||||
|
|
||||||
|
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.32", "4")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test // GH-3775
|
@Test // GH-3775
|
||||||
void mapNestedMixedStringIntegerFieldCorrectly() {
|
void mapNestedMixedStringIntegerFieldCorrectly() {
|
||||||
|
|
||||||
@@ -1720,6 +1730,8 @@ class UpdateMapperUnitTests {
|
|||||||
|
|
||||||
static class EntityWithNestedMap {
|
static class EntityWithNestedMap {
|
||||||
Map<String, Map<String, Map<String, Object>>> levelOne;
|
Map<String, Map<String, Map<String, Object>>> levelOne;
|
||||||
|
// for test mapNestedLastBigIntegerFieldCorrectly()
|
||||||
|
Map<String, Map<String, Map<String, Object>>> levelOne2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Customer {
|
static class Customer {
|
||||||
|
|||||||
Reference in New Issue
Block a user