Skip to content

Commit 478ea20

Browse files
committed
#922 Do not parse escapes within double quotes
1 parent 8619500 commit 478ea20

3 files changed

Lines changed: 37 additions & 15 deletions

File tree

src/docs/asciidoc/release_notes.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ This results in two minor breaking changes:
5151
+
5252
** Reserved words are no longer considered simple identifiers by `enquoteIdentifier` and `isSimpleIdentifier` and will be quoted (or -- for dialect 1 -- result in a `SQLFeatureNotSupportedException`)
5353
** Presence of the NUL character (U+0000) in an identifier passed to `enquoteIdentifier` will result in a `SQLSyntaxErrorException`
54+
* Fixed: JDBC escapes should not be parsed inside dialect 3 delimited identifiers or dialect 1 string literals (https://github.com/FirebirdSQL/jaybird/issues/922[#922])
5455
5556
[#jaybird-5-0-11-changelog]
5657
=== Jaybird 5.0.11

src/main/org/firebirdsql/jdbc/escape/FBEscapedParser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public static String parse(final String sql) throws SQLException {
120120
continue;
121121
case NORMAL_STATE:
122122
case LITERAL_STATE:
123+
case DELIMITED_IDENTIFIER:
123124
case START_LINE_COMMENT:
124125
case LINE_COMMENT:
125126
case START_BLOCK_COMMENT:
@@ -415,6 +416,8 @@ protected ParserState nextState(char inputChar) {
415416
switch (inputChar) {
416417
case '\'':
417418
return LITERAL_STATE;
419+
case '"':
420+
return DELIMITED_IDENTIFIER;
418421
case '{':
419422
return ESCAPE_ENTER_STATE;
420423
case '}':
@@ -440,6 +443,15 @@ protected ParserState nextState(char inputChar) {
440443
return (inputChar == '\'') ? NORMAL_STATE : LITERAL_STATE;
441444
}
442445
},
446+
/**
447+
* Dialect 3 delimited identifier or dialect 1 literal text (text inside double quotes).
448+
*/
449+
DELIMITED_IDENTIFIER {
450+
@Override
451+
protected ParserState nextState(char inputChar) {
452+
return (inputChar == '"') ? NORMAL_STATE : DELIMITED_IDENTIFIER;
453+
}
454+
},
443455
/**
444456
* Start of JDBC escape ({ character encountered).
445457
*/

src/test/org/firebirdsql/jdbc/escape/FBEscapedParserTest.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,22 +361,31 @@ void testQLiteral_InLiteralEndOfString_throwsParseException() {
361361
"Unexpected end of string at parser state Q_LITERAL_START");
362362
}
363363

364-
@Test
365-
void testQLiteralSpecials() throws Exception {
366-
checkQLiteralSpecialsBalancedStartEnd('(', ')');
367-
checkQLiteralSpecialsBalancedStartEnd(')', ')');
368-
checkQLiteralSpecialsBalancedStartEnd('{', '}');
369-
checkQLiteralSpecialsBalancedStartEnd('}', '}');
370-
checkQLiteralSpecialsBalancedStartEnd('[', ']');
371-
checkQLiteralSpecialsBalancedStartEnd(']', ']');
372-
checkQLiteralSpecialsBalancedStartEnd('<', '>');
373-
checkQLiteralSpecialsBalancedStartEnd('>', '>');
374-
}
375-
376-
private void checkQLiteralSpecialsBalancedStartEnd(char start, char end) throws Exception {
364+
@ParameterizedTest
365+
@CsvSource(useHeadersInDisplayName = true, value = {
366+
"start, end",
367+
"(, )",
368+
"), )",
369+
"{, }",
370+
"[, ]",
371+
"], ]",
372+
"<, >",
373+
">, >"
374+
})
375+
void checkQLiteralSpecialsBalancedStartEnd(char start, char end) throws Exception {
377376
final String input = "q'" + start + " {fn EXP(2)} " + end + "'";
378377

379-
String parseResult = FBEscapedParser.toNativeSql(input);
380-
assertEquals(input, parseResult, "Unexpected output");
378+
assertEquals(input, FBEscapedParser.toNativeSql(input), "Unexpected output");
381379
}
380+
381+
@ParameterizedTest
382+
@ValueSource(strings = {
383+
"'{fn EXP(2)}'",
384+
"q'{{fn EXP(2)}}'",
385+
"\"{fn EXP(2)}\""
386+
})
387+
void escapesInLiteralsOrDelimitedIdentifiers_notAnEscape(String input) throws Exception {
388+
assertEquals(input, FBEscapedParser.toNativeSql(input), "Unexpected output");
389+
}
390+
382391
}

0 commit comments

Comments
 (0)