Fix case where the from clause is misidentified.
Add a zero-width word boundary to the regex that identifies the from clause. This is used in alias detection. See #2508, #2260.
This commit is contained in:
committed by
Greg L. Turnquist
parent
28a22830bd
commit
cd27f03915
@@ -138,7 +138,7 @@ public abstract class QueryUtils {
|
||||
static {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("(?<=from)"); // from as starting delimiter
|
||||
builder.append("(?<=\\bfrom)"); // from as starting delimiter
|
||||
builder.append("(?:\\s)+"); // at least one space separating
|
||||
builder.append(IDENTIFIER_GROUP); // Entity name, can be qualified (any
|
||||
builder.append("(?:\\sas)*"); // exclude possible "as" keyword
|
||||
|
||||
@@ -130,6 +130,18 @@ class QueryUtilsUnitTests {
|
||||
assertThat(detectAlias(
|
||||
"(from Foo f max(f) ((((select * from Foo f2 (from Foo f3) max(*)) (from Foo f4)) max(f5)) (f6)) (from Foo f7))"))
|
||||
.isEqualTo("f");
|
||||
assertThat(detectAlias(
|
||||
"SELECT e FROM DbEvent e WHERE (CAST(:modifiedFrom AS date) IS NULL OR e.modificationDate >= :modifiedFrom)"))
|
||||
.isEqualTo("e");
|
||||
assertThat(detectAlias("from User u where (cast(:effective as date) is null) OR :effective >= u.createdAt"))
|
||||
.isEqualTo("u");
|
||||
assertThat(detectAlias("from User u where (cast(:effectiveDate as date) is null) OR :effectiveDate >= u.createdAt"))
|
||||
.isEqualTo("u");
|
||||
assertThat(detectAlias("from User u where (cast(:effectiveFrom as date) is null) OR :effectiveFrom >= u.createdAt"))
|
||||
.isEqualTo("u");
|
||||
assertThat(
|
||||
detectAlias("from User u where (cast(:e1f2f3ectiveFrom as date) is null) OR :effectiveFrom >= u.createdAt"))
|
||||
.isEqualTo("u");
|
||||
}
|
||||
|
||||
@Test // GH-2260
|
||||
|
||||
Reference in New Issue
Block a user