mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bugfix for \n
This commit is contained in:
@@ -674,17 +674,21 @@ public class Lexer {
|
||||
|
||||
ch = charAt(++pos);
|
||||
|
||||
if(ch == '\\') {
|
||||
hasSpecial = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == '\"' && charAt(pos - 1) != '\\') {
|
||||
scanChar();
|
||||
token = LITERAL_ALIAS;
|
||||
break;
|
||||
}
|
||||
|
||||
if(ch == '\\') {
|
||||
scanChar();
|
||||
if (ch == '"') {
|
||||
hasSpecial = true;
|
||||
} else {
|
||||
unscan();
|
||||
}
|
||||
}
|
||||
|
||||
if (bufPos == buf.length) {
|
||||
putChar(ch);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.alibaba.druid.bvt.bug;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsOutputVisitor;
|
||||
|
||||
public class Bug_for_qianbi extends TestCase {
|
||||
|
||||
public void test_for_issue() throws Exception {
|
||||
String sql = "insert into table lol select detail(sellerid,id) as count1,sum(sellerid) as sum1 from ctu_trade_paid_done.time('natural','1d','1h') "
|
||||
+ "where match(auctionTitle,\"男鞋\\n中石化&加油卡\\n中石化&充值卡\\n中石化&冲值卡\\n中石化&代冲\\n中石化&代充\\n中国石化&加油卡\\n中国石化&充值卡\\n中国石化&冲值卡\\n中国石化&代冲\\n中国石化&代充\",\"\\n\")";
|
||||
|
||||
String expected = "INSERT INTO TABLE lol"
|
||||
+ "\nSELECT detail(sellerid, id) AS count1, "
|
||||
+ "\n\tSUM(sellerid) AS sum1"
|
||||
+ "\nFROM ctu_trade_paid_done:time('natural', '1d', '1h')"
|
||||
+ "\nWHERE match(auctionTitle, '男鞋\\n中石化&加油卡\\n中石化&充值卡\\n中石化&冲值卡\\n中石化&代冲\\n中石化&代充\\n中国石化&加油卡\\n中国石化&充值卡\\n中国石化&冲值卡\\n中国石化&代冲\\n中国石化&代充', '\\n');\n";
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
OdpsOutputVisitor visitor = new OdpsOutputVisitor(out);
|
||||
OdpsStatementParser parser = new OdpsStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
for (SQLStatement statement : statementList) {
|
||||
statement.accept(visitor);
|
||||
visitor.print(";");
|
||||
visitor.println();
|
||||
}
|
||||
|
||||
// System.out.println(out.toString());
|
||||
|
||||
Assert.assertEquals(expected, out.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user