From cbc6c147dff2b5f717f25c19904015fa28321d97 Mon Sep 17 00:00:00 2001 From: Piotr Tokarski Date: Tue, 20 Jul 2021 11:20:29 +0200 Subject: [PATCH] Do not allow to parse line breaks between quotes in sniffer regexes. --- Lib/csv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/csv.py b/Lib/csv.py index dc85077f3ec6636..93f9fc7260c6d83 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -214,10 +214,10 @@ def _guess_quote_and_delimiter(self, data, delimiters): """ matches = [] - for restr in (r'(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?P=delim)', # ,".*?", - r'(?:^|\n)(?P["\']).*?(?P=quote)(?P[^\w\n"\'])(?P ?)', # ".*?", - r'(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?:$|\n)', # ,".*?" - r'(?:^|\n)(?P["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) + for restr in (r'(?P[^\w\n"\'])(?P ?)(?P["\'])[^\n]*?(?P=quote)(?P=delim)', # ,".*?", + r'(?:^|\n)(?P["\'])[^\n]*?(?P=quote)(?P[^\w\n"\'])(?P ?)', # ".*?", + r'(?P[^\w\n"\'])(?P ?)(?P["\'])[^\n]*?(?P=quote)(?:$|\n)', # ,".*?" + r'(?:^|\n)(?P["\'])[^\n]*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) regexp = re.compile(restr, re.DOTALL | re.MULTILINE) matches = regexp.findall(data) if matches: