DATACMNS-139 - Fixed potential StackOverflowException in PropertyPath.
When trying to access an inexistent property starting with an underscore (e.g. _id) PropertyPath.create(…) ran into a StackOverflowException. Changed the traversing regular expression to expect at least one capital letter for further traversals.
This commit is contained in:
@@ -321,7 +321,7 @@ public class PropertyPath implements Iterable<PropertyPath> {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern.compile("[A-Z]?[a-z]*$");
|
||||
Pattern pattern = Pattern.compile("[A-Z]+[a-z]*$");
|
||||
Matcher matcher = pattern.matcher(source);
|
||||
|
||||
if (matcher.find() && matcher.start() != 0) {
|
||||
|
||||
@@ -18,14 +18,11 @@ package org.springframework.data.mapping;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.mapping.PropertyPath;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PropertyPath}.
|
||||
@@ -169,6 +166,45 @@ public class PropertyUnitTests {
|
||||
assertThat(iterator.hasNext(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-139
|
||||
*/
|
||||
@Test
|
||||
public void rejectsInvalidPropertyWithLeadingUnderscore() {
|
||||
try {
|
||||
PropertyPath.from("_id", Foo.class);
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("property _id"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-139
|
||||
*/
|
||||
@Test
|
||||
public void rejectsNestedInvalidPropertyWithLeadingUnderscore() {
|
||||
try {
|
||||
PropertyPath.from("_foo_id", Sample2.class);
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("property id"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-139
|
||||
*/
|
||||
@Test
|
||||
public void rejectsNestedInvalidPropertyExplictlySplitWithLeadingUnderscore() {
|
||||
try {
|
||||
PropertyPath.from("_foo__id", Sample2.class);
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("property _id"));
|
||||
}
|
||||
}
|
||||
|
||||
private class Foo {
|
||||
|
||||
String userName;
|
||||
|
||||
Reference in New Issue
Block a user