https://github.com/python/cpython/commit/a3327dbfd4db9e5ad1ca514963d503abbbbfede7
commit: a3327dbfd4db9e5ad1ca514963d503abbbbfede7
branch: main
author: MikoĊ‚aj Kuranowski <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-07-25T10:04:47+03:00
summary:

gh-113785: csv: fields starting with escapechar are not quoted (GH-122110)

files:
A Misc/NEWS.d/next/Library/2024-07-22-08-14-04.gh-issue-113785.6B_KNB.rst
M Lib/test/test_csv.py
M Modules/_csv.c

diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index d74ab7e016f78c..c718ee1203cbe0 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -454,6 +454,10 @@ def test_read_quoting(self):
                           quoting=csv.QUOTE_STRINGS)
         self._read_test(['1,@,3,@,5'], [['1', ',3,', '5']], quotechar='@')
         self._read_test(['1,\0,3,\0,5'], [['1', ',3,', '5']], quotechar='\0')
+        self._read_test(['1\\.5,\\.5,.5'], [[1.5, 0.5, 0.5]],
+                        quoting=csv.QUOTE_NONNUMERIC, escapechar='\\')
+        self._read_test(['1\\.5,\\.5,"\\.5"'], [[1.5, 0.5, ".5"]],
+                        quoting=csv.QUOTE_STRINGS, escapechar='\\')
 
     def test_read_skipinitialspace(self):
         self._read_test(['no space, space,  spaces,\ttab'],
diff --git 
a/Misc/NEWS.d/next/Library/2024-07-22-08-14-04.gh-issue-113785.6B_KNB.rst 
b/Misc/NEWS.d/next/Library/2024-07-22-08-14-04.gh-issue-113785.6B_KNB.rst
new file mode 100644
index 00000000000000..89d44a3f79c390
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-07-22-08-14-04.gh-issue-113785.6B_KNB.rst
@@ -0,0 +1 @@
+:mod:`csv` now correctly parses numeric fields (when used with 
:const:`csv.QUOTE_NONNUMERIC` or :const:`csv.QUOTE_STRINGS`) which start with 
an escape character.
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 9964c383b8ad09..737b2c7468e13c 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -749,7 +749,6 @@ parse_process_char(ReaderObj *self, _csvstate 
*module_state, Py_UCS4 c)
         }
         else if (c == dialect->escapechar) {
             /* possible escaped character */
-            self->unquoted_field = false;
             self->state = ESCAPED_CHAR;
         }
         else if (c == ' ' && dialect->skipinitialspace)

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to