mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) (GH-122259)
(cherry picked from commit a3327dbfd4
)
Co-authored-by: Mikołaj Kuranowski <mkuranowski@gmail.com>
This commit is contained in:
parent
c57a33d006
commit
9d7209fc93
3 changed files with 5 additions and 0 deletions
|
@ -425,6 +425,8 @@ class Test_Csv(unittest.TestCase):
|
||||||
quoting=csv.QUOTE_NONNUMERIC)
|
quoting=csv.QUOTE_NONNUMERIC)
|
||||||
self._read_test(['1,@,3,@,5'], [['1', ',3,', '5']], quotechar='@')
|
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,\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):
|
def test_read_skipinitialspace(self):
|
||||||
self._read_test(['no space, space, spaces,\ttab'],
|
self._read_test(['no space, space, spaces,\ttab'],
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
:mod:`csv` now correctly parses numeric fields (when used with :const:`csv.QUOTE_NONNUMERIC`) which start with an escape character.
|
|
@ -701,6 +701,8 @@ parse_process_char(ReaderObj *self, _csvstate *module_state, Py_UCS4 c)
|
||||||
}
|
}
|
||||||
else if (c == dialect->escapechar) {
|
else if (c == dialect->escapechar) {
|
||||||
/* possible escaped character */
|
/* possible escaped character */
|
||||||
|
if (dialect->quoting == QUOTE_NONNUMERIC)
|
||||||
|
self->numeric_field = 1;
|
||||||
self->state = ESCAPED_CHAR;
|
self->state = ESCAPED_CHAR;
|
||||||
}
|
}
|
||||||
else if (c == ' ' && dialect->skipinitialspace)
|
else if (c == ' ' && dialect->skipinitialspace)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue