Skip to content

Commit 6933c4a

Browse files
[3.13] gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) (GH-122258)
(cherry picked from commit a3327db) Co-authored-by: Mikołaj Kuranowski <mkuranowski@gmail.com>
1 parent 94db4cc commit 6933c4a

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Lib/test/test_csv.py

+4
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ def test_read_quoting(self):
454454
quoting=csv.QUOTE_STRINGS)
455455
self._read_test(['1,@,3,@,5'], [['1', ',3,', '5']], quotechar='@')
456456
self._read_test(['1,\0,3,\0,5'], [['1', ',3,', '5']], quotechar='\0')
457+
self._read_test(['1\\.5,\\.5,.5'], [[1.5, 0.5, 0.5]],
458+
quoting=csv.QUOTE_NONNUMERIC, escapechar='\\')
459+
self._read_test(['1\\.5,\\.5,"\\.5"'], [[1.5, 0.5, ".5"]],
460+
quoting=csv.QUOTE_STRINGS, escapechar='\\')
457461

458462
def test_read_skipinitialspace(self):
459463
self._read_test(['no space, space, spaces,\ttab'],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

Modules/_csv.c

-1
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,6 @@ parse_process_char(ReaderObj *self, _csvstate *module_state, Py_UCS4 c)
749749
}
750750
else if (c == dialect->escapechar) {
751751
/* possible escaped character */
752-
self->unquoted_field = false;
753752
self->state = ESCAPED_CHAR;
754753
}
755754
else if (c == ' ' && dialect->skipinitialspace)

0 commit comments

Comments
 (0)