New submission from Dave Challis: When attempting to detect the presence of CSV headers, delimiters are passed to a regex function without escaping, which causes an exception if a delimiter which has meaning in a regex (e.g. '+', '*' etc.) is used.
Code to reproduce: import csv s = csv.Sniffer() s.has_header('"x"+"y"') Trace: Traceback (most recent call last): File "t.py", line 4, in <module> s.has_header('"x"+"y"') File "/usr/lib64/python3.3/csv.py", line 393, in has_header rdr = reader(StringIO(sample), self.sniff(sample)) File "/usr/lib64/python3.3/csv.py", line 183, in sniff self._guess_quote_and_delimiter(sample, delimiters) File "/usr/lib64/python3.3/csv.py", line 268, in _guess_quote_and_delimiter {'delim':delim, 'quote':quotechar}, re.MULTILINE) File "/home/dsc/venv/p3compat/lib64/python3.3/re.py", line 214, in compile return _compile(pattern, flags) File "/home/dsc/venv/p3compat/lib64/python3.3/re.py", line 281, in _compile p = sre_compile.compile(pattern, flags) File "/home/dsc/venv/p3compat/lib64/python3.3/sre_compile.py", line 494, in compile p = sre_parse.parse(p, flags) File "/home/dsc/venv/p3compat/lib64/python3.3/sre_parse.py", line 748, in parse p = _parse_sub(source, pattern, 0) File "/home/dsc/venv/p3compat/lib64/python3.3/sre_parse.py", line 360, in _parse_sub itemsappend(_parse(source, state)) File "/home/dsc/venv/p3compat/lib64/python3.3/sre_parse.py", line 696, in _parse p = _parse_sub(source, state) File "/home/dsc/venv/p3compat/lib64/python3.3/sre_parse.py", line 360, in _parse_sub itemsappend(_parse(source, state)) File "/home/dsc/venv/p3compat/lib64/python3.3/sre_parse.py", line 696, in _parse p = _parse_sub(source, state) File "/home/dsc/venv/p3compat/lib64/python3.3/sre_parse.py", line 360, in _parse_sub itemsappend(_parse(source, state)) File "/home/dsc/venv/p3compat/lib64/python3.3/sre_parse.py", line 569, in _parse raise error("nothing to repeat") sre_constants.error: nothing to repeat ---------- components: Library (Lib) messages: 190742 nosy: davechallis priority: normal severity: normal status: open title: csv.Sniffer.has_header doesn't escape characters used in regex type: behavior versions: Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18155> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com