Skip to content

Commit 56c5388

Browse files
fix: remove \n and \r exclusion from quoted identifiers (#2936)
* fix: remove new line and carrige return exclusion from quouted identifiers * fix: spotless apply
1 parent bb47b9d commit 56c5388

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6992,10 +6992,10 @@ TOKEN:
69926992
lexUnicodeEscapeString(matchedToken);
69936993
}
69946994
}
6995-
| < S_QUOTED_IDENTIFIER: "\"" ( "\"\"" | ~["\n","\r","\""])* "\""
6995+
| < S_QUOTED_IDENTIFIER: "\"" ( "\"\"" | ~["\""])* "\""
69966996
// MySQL double-quoted string with backslash escapes; trimmed below when not enabled
6997-
| "\"" ( "\"\"" | "\\" ~["\n","\r"] | ~["\n","\r","\"","\\"])* "\""
6998-
| ("`" ("``" | ~["\n","\r","`"])* "`") | ( "[" (~["\n","\r","]"])* "]" ) >
6997+
| "\"" ( "\"\"" | "\\" ~[] | ~["\"","\\"])* "\""
6998+
| ("`" ("``" | ~["`"])* "`") | ( "[" (~["]"])* "]" ) >
69996999
{
70007000
if ( matchedToken.image.charAt(0) == '"' ) {
70017001
// Both alternatives above compete for the longest match. Keep the closing quote of

‎src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6725,6 +6725,17 @@ void testClickHouseArrayJoin() throws Exception {
67256725
Assertions.assertFalse(joinInner.isLeft(), "Should not be a left join");
67266726
}
67276727

6728+
@Test
6729+
void testQuotedIdentifierContainingNewline() throws Exception {
6730+
// the newline is part of the identifier and must survive parse and deparse unchanged
6731+
String sql = "SELECT \"Planned/\nUnplanned\" FROM t";
6732+
TestUtils.assertSqlCanBeParsedAndDeparsed(sql, true);
6733+
6734+
PlainSelect select = (PlainSelect) CCJSqlParserUtil.parse(sql);
6735+
Column column = (Column) select.getSelectItem(0).getExpression();
6736+
Assertions.assertEquals("\"Planned/\nUnplanned\"", column.getColumnName());
6737+
}
6738+
67286739
@Test
67296740
void testSnowflakeArrayCastOnVariantPathInFlatten() throws Exception {
67306741
String sql = "CREATE OR REPLACE TABLE \"DB\".\"S\".\"T\" COPY GRANTS\n"

0 commit comments

Comments
 (0)