Skip to content

Commit

Permalink
DATAJPA-1500 - Fix RegEx to support whitespace characters at the end.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
florianluediger authored and schauder committed Jun 5, 2019
1 parent 3f4376c commit 6e23178
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,15 @@ public void detectsAliasWithGroupAndOrderBy() {
assertThat(detectAlias("select * from User u order by name")).isEqualTo("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));
}
Expand Down

0 comments on commit 6e23178

Please sign in to comment.