Commit d41dc7ce authored by Senthil Kumaran's avatar Senthil Kumaran

2.7 : Issue #16013: Fix CSV Reader parsing issue with ending quote characters....

2.7 : Issue #16013: Fix CSV Reader parsing issue with ending quote characters. Patch by Serhiy Storchaka.
parent 3dec449a
...@@ -243,6 +243,15 @@ class Test_Csv(unittest.TestCase): ...@@ -243,6 +243,15 @@ class Test_Csv(unittest.TestCase):
self.assertRaises(csv.Error, self._read_test, ['a,b\nc,d'], []) self.assertRaises(csv.Error, self._read_test, ['a,b\nc,d'], [])
self.assertRaises(csv.Error, self._read_test, ['a,b\r\nc,d'], []) self.assertRaises(csv.Error, self._read_test, ['a,b\r\nc,d'], [])
def test_read_eof(self):
self._read_test(['a,"'], [['a', '']])
self._read_test(['"a'], [['a']])
self._read_test(['^'], [['\n']], escapechar='^')
self.assertRaises(csv.Error, self._read_test, ['a,"'], [], strict=True)
self.assertRaises(csv.Error, self._read_test, ['"a'], [], strict=True)
self.assertRaises(csv.Error, self._read_test,
['^'], [], escapechar='^', strict=True)
def test_read_escape(self): def test_read_escape(self):
self._read_test(['a,\\b,c'], [['a', 'b', 'c']], escapechar='\\') self._read_test(['a,\\b,c'], [['a', 'b', 'c']], escapechar='\\')
self._read_test(['a,b\\,c'], [['a', 'b,c']], escapechar='\\') self._read_test(['a,b\\,c'], [['a', 'b,c']], escapechar='\\')
......
...@@ -103,6 +103,9 @@ Core and Builtins ...@@ -103,6 +103,9 @@ Core and Builtins
Library Library
------- -------
- Issue #16013: Fix CSV Reader parsing issue with ending quote characters.
Patch by Serhiy Storchaka.
- Issue #15421: fix an OverflowError in Calendar.itermonthdates() after - Issue #15421: fix an OverflowError in Calendar.itermonthdates() after
datetime.MAXYEAR. Patch by Cédric Krier. datetime.MAXYEAR. Patch by Cédric Krier.
......
...@@ -788,9 +788,13 @@ Reader_iternext(ReaderObj *self) ...@@ -788,9 +788,13 @@ Reader_iternext(ReaderObj *self)
lineobj = PyIter_Next(self->input_iter); lineobj = PyIter_Next(self->input_iter);
if (lineobj == NULL) { if (lineobj == NULL) {
/* End of input OR exception */ /* End of input OR exception */
if (!PyErr_Occurred() && self->field_len != 0) if (!PyErr_Occurred() && (self->field_len != 0 ||
PyErr_Format(error_obj, self->state == IN_QUOTED_FIELD)) {
"newline inside string"); if (self->dialect->strict)
PyErr_SetString(error_obj, "unexpected end of data");
else if (parse_save_field(self) >= 0 )
break;
}
return NULL; return NULL;
} }
++self->line_num; ++self->line_num;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment