Skip to content

Commit

Permalink
Fix parsing entity names in HQL query with package names that contain…
Browse files Browse the repository at this point in the history
… reserved exp keyword.

Resolves: #3451
Original pull request: #3457
  • Loading branch information
christophstrobl authored and mp911de committed Apr 30, 2024
1 parent 4c263f1 commit 6a2510d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ reservedWord
| EXCEPT
| EXCLUDE
| EXISTS
| EXP
| EXTRACT
| FETCH
| FILTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.jpa.repository.query.JpaQueryParsingToken.*;

import java.util.stream.Stream;

import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

/**
Expand Down Expand Up @@ -55,6 +59,10 @@ private static String parseWithoutChanges(String query) {
return render(new HqlQueryRenderer().visit(parsedQuery));
}

public static Stream<Arguments> reservedWords() {
return Stream.of("abs", "exp", "any", "case", "else", "index", "time").map(Arguments::of);
}

private void assertQuery(String query) {

String slimmedDownQuery = reduceWhitespace(query);
Expand Down Expand Up @@ -1659,4 +1667,12 @@ void signedLiteralShouldWork(String query) {
void signedExpressionsShouldWork(String query) {
assertQuery(query);
}

@ParameterizedTest // GH-3451
@MethodSource({"reservedWords"})
void entityNameWithPackageContainingReservedWord(String reservedWord) {

String source = "select new com.company.%s.thing.stuff.ClassName(e.id) from Experience e".formatted(reservedWord);
assertQuery(source);
}
}

0 comments on commit 6a2510d

Please sign in to comment.