Commits

Armin Rigo committed 08dbc60

Test and fix from CPython: http://bugs.python.org/issue16013

  • Participants
  • Parent commits e31552c

Comments (0)

Files changed (2)

File pypy/module/_csv/interp_reader.py

                 w_line = space.next(self.w_iter)
             except OperationError, e:
                 if e.match(space, space.w_StopIteration):
-                    if field_builder is not None:
-                        raise self.error("newline inside string")
+                    if (state != START_RECORD and state != EAT_CRNL and
+                            (len(field_builder.build()) > 0 or
+                             state == IN_QUOTED_FIELD)):
+                        if dialect.strict:
+                            raise self.error("newline inside string")
+                        else:
+                            self.save_field(field_builder)
+                            break
                 raise
             self.line_num += 1
             line = space.str_w(w_line)

File pypy/module/_csv/test/test_reader.py

 
     def test_dubious_quote(self):
         self._read_test(['12,12,1",'], [['12', '12', '1"', '']])
+
+    def test_read_eof(self):
+        self._read_test(['a,"'], [['a', '']])
+        self._read_test(['"a'], [['a']])
+        self._read_test(['^'], [['\n']], escapechar='^')
+        self._read_test(['a,"'], 'Error', strict=True)
+        self._read_test(['"a'], 'Error', strict=True)
+        self._read_test(['^'], 'Error', escapechar='^', strict=True)