File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
main/java/org/springframework/data/jpa/repository/query
test/java/org/springframework/data/jpa/repository/query Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ public abstract class QueryUtils {
84
84
private static final String IDENTIFIER = "[\\ p{Lu}\\ P{InBASIC_LATIN}\\ p{Alnum}._$]+" ;
85
85
private static final String IDENTIFIER_GROUP = String .format ("(%s)" , IDENTIFIER );
86
86
87
- private static final String JOIN = "join " + IDENTIFIER + " (as )?" + IDENTIFIER_GROUP ;
87
+ private static final String JOIN = "join\\ s " + IDENTIFIER + "\\ s (as\\ s )?" + IDENTIFIER_GROUP ;
88
88
private static final Pattern JOIN_PATTERN = Pattern .compile (JOIN , Pattern .CASE_INSENSITIVE );
89
89
90
90
private static final String EQUALS_CONDITION_STRING = "%s.%s = :%s" ;
@@ -102,10 +102,10 @@ public abstract class QueryUtils {
102
102
103
103
StringBuilder builder = new StringBuilder ();
104
104
builder .append ("(?<=from)" ); // from as starting delimiter
105
- builder .append ("(?: )+" ); // at least one space separating
105
+ builder .append ("(?:\\ s )+" ); // at least one space separating
106
106
builder .append (IDENTIFIER_GROUP ); // Entity name, can be qualified (any
107
- builder .append ("(?: as )*" ); // exclude possible "as" keyword
108
- builder .append ("(?: )+" ); // at least one space separating
107
+ builder .append ("(?:\\ sas )*" ); // exclude possible "as" keyword
108
+ builder .append ("(?:\\ s )+" ); // at least one space separating
109
109
builder .append ("(\\ w*)" ); // the actual alias
110
110
111
111
ALIAS_MATCH = compile (builder .toString (), CASE_INSENSITIVE );
Original file line number Diff line number Diff line change @@ -303,6 +303,14 @@ public void supportsNonAsciiCharactersInEntityNames() {
303
303
assertThat (createCountQueryFor ("select u from Usèr u" ), is ("select count(u) from Usèr u" ));
304
304
}
305
305
306
+ /**
307
+ * @see DATAJPA-798
308
+ */
309
+ @ Test
310
+ public void detectsAliasInQueryContainingLineBreaks () {
311
+ assertThat (detectAlias ("select \n u \n from \n User \n u" ), is ("u" ));
312
+ }
313
+
306
314
private void assertCountQuery (String originalQuery , String countQuery ) {
307
315
assertThat (createCountQueryFor (originalQuery ), is (countQuery ));
308
316
}
You can’t perform that action at this time.
0 commit comments