Skip to content

Commit

Permalink
DATACMNS-139 - Fixed potential StackOverflowException in PropertyPath.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odrotbohm committed Apr 11, 2012
1 parent 109e7f9 commit f3d037b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Expand Up @@ -321,7 +321,7 @@ private static PropertyPath create(String source, TypeInformation<?> type, Strin
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) {
Expand Down
Expand Up @@ -18,14 +18,11 @@
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}.
Expand Down Expand Up @@ -169,6 +166,45 @@ public void returnsCorrectIteratorForMultipleElement() {
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;
Expand Down

0 comments on commit f3d037b

Please sign in to comment.