Skip to content

Commit 096d2b2

Browse files
lzmhhh123ngaut
authored andcommitted
parser: fix bug empty string in "ESCAPED BY" subclause of "FIELDS" cause panic (#7880) (#8005)
1 parent 59d6a93 commit 096d2b2

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

parser/parser.y

+5-1
Original file line numberDiff line numberDiff line change
@@ -7013,10 +7013,14 @@ Fields:
70137013
}else if len(str) != 0 {
70147014
enclosed = str[0]
70157015
}
7016+
var escaped byte
7017+
if len(escape) > 0 {
7018+
escaped = escape[0]
7019+
}
70167020
$$ = &ast.FieldsClause{
70177021
Terminated: $2.(string),
70187022
Enclosed: enclosed,
7019-
Escaped: escape[0],
7023+
Escaped: escaped,
70207024
}
70217025
}
70227026

parser/parser_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ func (s *testParserSuite) TestDMLStmt(c *C) {
394394
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' (a,b) ignore 1 lines", false},
395395
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab' terminated by 'xy' ignore 1 lines", true},
396396
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' escaped by '*' ignore 1 lines (a,b)", true},
397+
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' escaped by ''", true},
397398

398399
// select for update
399400
{"SELECT * from t for update", true},

0 commit comments

Comments
 (0)