Skip to content

[3.12] gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) #122259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`csv` now correctly parses numeric fields (when used with :const:`csv.QUOTE_NONNUMERIC`) which start with an escape character.
2 changes: 2 additions & 0 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading