summaryrefslogtreecommitdiffstats
path: root/Modules/_csv.c
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-03-20 02:41:47 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-03-20 02:41:47 (GMT)
commitc7c42efb16612f66af266073937cffa99ad49a33 (patch)
tree2653077e3c508f41ac849282d53d801c1779f76a /Modules/_csv.c
parent04cbe0c35b20c8379baf55cc5e152f88449e5202 (diff)
downloadcpython-c7c42efb16612f66af266073937cffa99ad49a33.zip
cpython-c7c42efb16612f66af266073937cffa99ad49a33.tar.gz
cpython-c7c42efb16612f66af266073937cffa99ad49a33.tar.bz2
#15927: Fix cvs.reader parsing of escaped \r\n with quoting off.
This fix means that such values are correctly roundtripped, since cvs.writer already does the correct escaping. Patch by Michael Johnson.
Diffstat (limited to 'Modules/_csv.c')
-rw-r--r--Modules/_csv.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 48a5cf8..39f9d7d 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -51,7 +51,7 @@ static struct PyModuleDef _csvmodule;
typedef enum {
START_RECORD, START_FIELD, ESCAPED_CHAR, IN_FIELD,
IN_QUOTED_FIELD, ESCAPE_IN_QUOTED_FIELD, QUOTE_IN_QUOTED_FIELD,
- EAT_CRNL
+ EAT_CRNL,AFTER_ESCAPED_CRNL
} ParserState;
typedef enum {
@@ -644,6 +644,12 @@ parse_process_char(ReaderObj *self, Py_UCS4 c)
break;
case ESCAPED_CHAR:
+ if (c == '\n' | c=='\r') {
+ if (parse_add_char(self, c) < 0)
+ return -1;
+ self->state = AFTER_ESCAPED_CRNL;
+ break;
+ }
if (c == '\0')
c = '\n';
if (parse_add_char(self, c) < 0)
@@ -651,6 +657,11 @@ parse_process_char(ReaderObj *self, Py_UCS4 c)
self->state = IN_FIELD;
break;
+ case AFTER_ESCAPED_CRNL:
+ if (c == '\0')
+ break;
+ /*fallthru*/
+
case IN_FIELD:
/* in unquoted field */
if (c == '\n' || c == '\r' || c == '\0') {