This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: small csv reader bug
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: arigo, orsenthil, python-dev, serhiy.storchaka
Priority: normal Keywords: needs review, patch

Created on 2012-09-24 13:03 by arigo, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
csv_eof-3.3.patch serhiy.storchaka, 2012-09-24 22:04 Patch for 3.3 review
csv_eof-3.2.patch serhiy.storchaka, 2012-09-24 22:05 Patch for 2.7 and 3.2 review
csv_eof_test.patch serhiy.storchaka, 2012-09-25 07:17 review
Messages (7)
msg171122 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2012-09-24 13:03
A small bug of cvs.reader():

>>> list(csv.reader(['foo:"'], delimiter=':', quotechar='"'))
[]

Adding strict=True doesn't change anything.  This is caused by the opening quote not followed by anything, which causes the error to be silently ignored and the last line to be dropped.
msg171186 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-09-24 20:27
A shorter example:

>>> import csv
>>> list(csv.reader(['foo,"']))
[]
msg171199 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-09-24 22:04
Here is a patch.

>>> list(csv.reader(['foo,"']))
[['foo', '']]
>>> list(csv.reader(['foo,"'], strict=1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_csv.Error: unexpected end of data
>>> list(csv.reader(['foo,^'], escapechar='^'))
[['foo', '\n']]
>>> list(csv.reader(['foo,^'], escapechar='^', strict=1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_csv.Error: unexpected end of data

Is it good?
msg171229 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-09-25 07:17
Here is a test.
msg171233 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-09-25 09:21
The patch looks good and is doing the right thing, that is, when the, strict mode is passed, it fails and without strict mode, it is printing the parsed list.
msg171235 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-09-25 09:37
New changeset e9c005676d6e by Senthil Kumaran in branch '3.2':
Issue #16013: Fix CSV Reader parsing issue with ending quote characters. Patch by Serhiy Storchaka.
http://hg.python.org/cpython/rev/e9c005676d6e

New changeset 25f0756deeae by Senthil Kumaran in branch 'default':
merge 3.2: Issue #16013: Fix CSV Reader parsing issue with ending quote characters. Patch by Serhiy Storchaka.
http://hg.python.org/cpython/rev/25f0756deeae
msg171237 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-09-25 09:48
New changeset 5f0465d0e91e by Senthil Kumaran in branch '2.7':
2.7 : Issue #16013: Fix CSV Reader parsing issue with ending quote characters. Patch by Serhiy Storchaka.
http://hg.python.org/cpython/rev/5f0465d0e91e
History
Date User Action Args
2022-04-11 14:57:36adminsetgithub: 60217
2012-10-20 20:41:33serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: test needed -> resolved
2012-09-25 09:48:42python-devsetmessages: + msg171237
2012-09-25 09:37:30python-devsetnosy: + python-dev
messages: + msg171235
2012-09-25 09:21:42orsenthilsetnosy: + orsenthil
messages: + msg171233
2012-09-25 07:17:16serhiy.storchakasetfiles: + csv_eof_test.patch

messages: + msg171229
2012-09-25 01:04:18eric.araujosetkeywords: + needs review
stage: test needed
2012-09-24 22:05:47serhiy.storchakasetfiles: + csv_eof-3.2.patch
2012-09-24 22:04:55serhiy.storchakasetfiles: + csv_eof-3.3.patch
keywords: + patch
messages: + msg171199
2012-09-24 20:27:13serhiy.storchakasetversions: + Python 3.2
nosy: + serhiy.storchaka

messages: + msg171186

type: behavior
2012-09-24 13:03:11arigocreate