DATAJPA-1500 - Fix RegEx to support whitespace characters at the end.
When using the creteCountQueryFor method before, the order by clause did not get removed when having a specific combination of whitespace characters at the end of the input. By removing the $ for matching the end of the line, this is now fixed. Original pull request: #380.
This commit is contained in:
committed by
Jens Schauder
parent
e703f13213
commit
1999da61ba
@@ -81,7 +81,7 @@ public abstract class QueryUtils {
|
||||
private static final String COUNT_REPLACEMENT_TEMPLATE = "select count(%s) $5$6$7";
|
||||
private static final String SIMPLE_COUNT_VALUE = "$2";
|
||||
private static final String COMPLEX_COUNT_VALUE = "$3$6";
|
||||
private static final String ORDER_BY_PART = "(?iu)\\s+order\\s+by\\s+.*$";
|
||||
private static final String ORDER_BY_PART = "(?iu)\\s+order\\s+by\\s+.*";
|
||||
|
||||
private static final Pattern ALIAS_MATCH;
|
||||
private static final Pattern COUNT_MATCH;
|
||||
|
||||
@@ -411,6 +411,15 @@ public class QueryUtilsUnitTests {
|
||||
assertThat(detectAlias("select * from User u order by name"), is("u"));
|
||||
}
|
||||
|
||||
@Test // DATAJPA-1500
|
||||
public void createCountQuerySupportsWhitespaceCharacters() {
|
||||
assertThat(createCountQueryFor("select * from User user\n" +
|
||||
" where user.age = 18\n" +
|
||||
" order by user.name\n "),
|
||||
is("select count(user) from User user\n" +
|
||||
" where user.age = 18\n "));
|
||||
}
|
||||
|
||||
private static void assertCountQuery(String originalQuery, String countQuery) {
|
||||
assertThat(createCountQueryFor(originalQuery), is(countQuery));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user