Repository navigation
Closed
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
in _guess_quote_and_delimiter function in csv.py, regular expressions end with "(?:$|\n)" won't be able to handle \r in windows line end
>>> import re
>>> re.search(r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', '2020-10-01 17:17:37+08:00,https://www.mozilla.org/en-US/firefox/welcome/2/,"Pocket - Save news, videos, stories and more"\r\n', re.M|re.S)
>>> re.search(r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\r|\n)', '2020-10-01 17:17:37+08:00,https://www.mozilla.org/en-US/firefox/welcome/2/,"Pocket - Save news, videos, stories and more"\r\n', re.M|re.S)
<re.Match object; span=(74, 122), match=',"Pocket - Save news, videos, stories and more"\r>
import csv
a = 'Timestamp,URL,Title\r\n2020-10-01 17:17:37+08:00,https://www.mozilla.org/en-US/firefox/welcome/2/,"Pocket - Save news, videos, stories and more"\r\n'
sniffer = csv.Sniffer()
result = sniffer.sniff(a)
print(result.delimiter)
print(result.quotechar)
The wrong output is "p"
After the change, output becomes ","
Your environment
Windows
- CPython versions tested on: 3.11.2
- Operating system and architecture: windows 64
Linked PRs
- gh-103925: csv.py _guess_quote_and_delimiter should be able to handle windows \r #103926
- [3.15] gh-103925: Fix csv.Sniffer for a quoted field ending a CRLF line (GH-103926) #154322
- [3.14] gh-103925: Fix csv.Sniffer for a quoted field ending a CRLF line (GH-103926) #154323
- [3.13] gh-103925: Fix csv.Sniffer for a quoted field ending a CRLF line (GH-103926) #154330
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
fix python#103925
fix python#103925
gh-103925: Fix csv.Sniffer for a quoted field ending a CRLF line (GH-…
[3.14] gh-103925: Fix csv.Sniffer for a quoted field ending a CRLF li…
[3.15] gh-103925: Fix csv.Sniffer for a quoted field ending a CRLF li…
[3.13] gh-103925: Fix csv.Sniffer for a quoted field ending a CRLF li…