https://github.com/python/cpython/commit/9d7209fc93922948ed3e65e6cfc339b833bc6677 commit: 9d7209fc93922948ed3e65e6cfc339b833bc6677 branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka <[email protected]> date: 2024-08-09T16:04:29Z summary:
[3.12] gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) (GH-122259) (cherry picked from commit a3327dbfd4db9e5ad1ca514963d503abbbbfede7) Co-authored-by: MikoĊaj Kuranowski <[email protected]> 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 adb89d0df926c6..57db59185d97f7 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -425,6 +425,8 @@ def test_read_quoting(self): quoting=csv.QUOTE_NONNUMERIC) 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='\\') 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..c1118740370a5e --- /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`) which start with an escape character. diff --git a/Modules/_csv.c b/Modules/_csv.c index d63eac1bf7a222..9a7b7d27c2ed39 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -701,6 +701,8 @@ parse_process_char(ReaderObj *self, _csvstate *module_state, Py_UCS4 c) } else if (c == dialect->escapechar) { /* possible escaped character */ + if (dialect->quoting == QUOTE_NONNUMERIC) + self->numeric_field = 1; 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]
