Skip to content

Commit

Permalink
Fix Java String literal parsing in JQPL grammar.
Browse files Browse the repository at this point in the history
Allow using java string literals using escaped double quotes next to single quoted values.
  • Loading branch information
christophstrobl committed Jan 10, 2024
1 parent 0d9c1e6 commit 3626638
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ constructor_item
| scalar_expression
| aggregate_expression
| identification_variable
| literal
;

aggregate_expression
Expand Down Expand Up @@ -620,6 +621,7 @@ constructor_name

literal
: STRINGLITERAL
| JAVASTRINGLITERAL
| INTLITERAL
| FLOATLITERAL
| LONGLITERAL
Expand Down Expand Up @@ -855,6 +857,7 @@ NOT_EQUAL : '<>' | '!=' ;
CHARACTER : '\'' (~ ('\'' | '\\')) '\'' ;
IDENTIFICATION_VARIABLE : ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '$' | '_') ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '0' .. '9' | '$' | '_')* ;
STRINGLITERAL : '\'' (~ ('\'' | '\\'))* '\'' ;
JAVASTRINGLITERAL : '"' ( ('\\' [btnfr"']) | ~('"'))* '"';
FLOATLITERAL : ('0' .. '9')* '.' ('0' .. '9')+ (E ('0' .. '9')+)* (F|D)?;
INTLITERAL : ('0' .. '9')+ ;
LONGLITERAL : ('0' .. '9')+L ;
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ public List<JpaQueryParsingToken> visitConstructor_item(JpqlParser.Constructor_i
tokens.addAll(visit(ctx.aggregate_expression()));
} else if (ctx.identification_variable() != null) {
tokens.addAll(visit(ctx.identification_variable()));
} else if (ctx.literal() != null) {
tokens.addAll(visit(ctx.literal()));
}

return tokens;
Expand Down Expand Up @@ -2153,6 +2155,8 @@ public List<JpaQueryParsingToken> visitLiteral(JpqlParser.LiteralContext ctx) {

if (ctx.STRINGLITERAL() != null) {
tokens.add(new JpaQueryParsingToken(ctx.STRINGLITERAL()));
} else if (ctx.JAVASTRINGLITERAL() != null) {
tokens.add(new JpaQueryParsingToken(ctx.JAVASTRINGLITERAL()));
} else if (ctx.INTLITERAL() != null) {
tokens.add(new JpaQueryParsingToken(ctx.INTLITERAL()));
} else if (ctx.FLOATLITERAL() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ void numericLiterals() {
assertQuery("SELECT s FROM Stat s WHERE s.ratio > 3.14e32D");
}

@Test // GH-3308
void newWithStrings() {
assertQuery("select new com.example.demo.SampleObject(se.id, se.sampleValue, \"java\") from SampleEntity se");
}

}

0 comments on commit 3626638

Please sign in to comment.