Skip to content

Commit df624c1

Browse files
committed
Fix case where the from clause is misidentified.
fixes spring-projects#2260 Added a zero-width word boundary to the regex that identifies the from clause. This is used in alias detection for order by clauses.
1 parent 28a2283 commit df624c1

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public abstract class QueryUtils {
138138
static {
139139

140140
StringBuilder builder = new StringBuilder();
141-
builder.append("(?<=from)"); // from as starting delimiter
141+
builder.append("(?<=\\bfrom)"); // from as starting delimiter
142142
builder.append("(?:\\s)+"); // at least one space separating
143143
builder.append(IDENTIFIER_GROUP); // Entity name, can be qualified (any
144144
builder.append("(?:\\sas)*"); // exclude possible "as" keyword

src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ void detectsAliasCorrectly() throws Exception {
130130
assertThat(detectAlias(
131131
"(from Foo f max(f) ((((select * from Foo f2 (from Foo f3) max(*)) (from Foo f4)) max(f5)) (f6)) (from Foo f7))"))
132132
.isEqualTo("f");
133+
assertThat(detectAlias(
134+
"SELECT e FROM DbEvent e WHERE (CAST(:modifiedFrom AS date) IS NULL OR e.modificationDate >= :modifiedFrom)"))
135+
.isEqualTo("e");
133136
}
134137

135138
@Test // GH-2260

0 commit comments

Comments
 (0)