Skip to content

CSV Writer can not write strings with nulls when no escapechar is specified #97503

@eshmu

Description

@eshmu

Bug report

This code fails in Python 3.10 with the need to escape, but no escapechar set error:

import csv

value = 'my\x00string'

with io.StringIO() as buf:
    writer = csv.writer(buf)
    writer.writerow([value])

However, this worked on Python 3.9 and earlier, and it should work since I shouldn't have to specify an escapechar when quoting is available.

I believe this is caused by the fix for this issue: #56387

See this comment on how the C snippet added for the fix introduced this bug: #56387 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtriagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions