1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-03 16:53:36 +03:00

Fix a bug in the shell ".import" command: Do not end the field

when an escaped double-quote occurs at the end of a CRNL line.

FossilOrigin-Name: 5e239ecda0f7835ce037b38b04627a574b5854cd
This commit is contained in:
drh
2013-12-11 14:00:04 +00:00
parent 39325bac1b
commit a81ad1758c
4 changed files with 31 additions and 11 deletions

View File

@@ -1836,7 +1836,7 @@ static void csv_append_char(CSVReader *p, int c){
** + Report syntax errors on stderr
*/
static char *csv_read_one_field(CSVReader *p){
int c, pc;
int c, pc, ppc;
int cSep = p->cSeparator;
p->n = 0;
c = fgetc(p->in);
@@ -1847,7 +1847,7 @@ static char *csv_read_one_field(CSVReader *p){
if( c=='"' ){
int startLine = p->nLine;
int cQuote = c;
pc = 0;
pc = ppc = 0;
while( 1 ){
c = fgetc(p->in);
if( c=='\n' ) p->nLine++;
@@ -1859,7 +1859,7 @@ static char *csv_read_one_field(CSVReader *p){
}
if( (c==cSep && pc==cQuote)
|| (c=='\n' && pc==cQuote)
|| (c=='\n' && pc=='\r' && p->n>=2 && p->z[p->n-2]==cQuote)
|| (c=='\n' && pc=='\r' && ppc==cQuote)
|| (c==EOF && pc==cQuote)
){
do{ p->n--; }while( p->z[p->n]!=cQuote );
@@ -1877,6 +1877,7 @@ static char *csv_read_one_field(CSVReader *p){
break;
}
csv_append_char(p, c);
ppc = pc;
pc = c;
}
}else{