GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — csv.Sniffer.snif doesn't set up the dialect properly for a csv created with dialect=csv.excel_tab and containing quote (") char · Issue #62029 · python/cpython

csv.Sniffer.snif doesn't set up the dialect properly for a csv created with dialect=csv.excel_tab and containing quote (") char #62029

New issue
Copy link
New issue
Copy link
Open
#153694
Open
csv.Sniffer.snif doesn't set up the dialect properly for a csv created with dialect=csv.excel_tab and containing quote (") char#62029
#153694
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs 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

GhislainHivon
mannequin
opened on Apr 24, 2013
Issue body actions
BPO 17829
Files
  • csv_sniffing_excel_tab.py: Exemple of sniffing csv with dialect=csv.excel_tab and quote in data
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2013-04-24.15:06:00.650>
    labels = ['type-bug']
    title = 'csv.Sniffer.snif doesn\'t set up the dialect properly for a csv created with dialect=csv.excel_tab and containing quote (") char'
    updated_at = <Date 2014-03-28.10:04:37.158>
    user = 'https://bugs.python.org/GhislainHivon'

    bugs.python.org fields:

    activity = <Date 2014-03-28.10:04:37.158>
    actor = 'Antoon.Pardon'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2013-04-24.15:06:00.650>
    creator = 'GhislainHivon'
    dependencies = []
    files = ['30001']
    hgrepos = []
    issue_num = 17829
    keywords = []
    message_count = 3.0
    messages = ['187709', '214800', '215031']
    nosy_count = 3.0
    nosy_names = ['GhislainHivon', 'Antoon.Pardon', 'dmi.baranov']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17829'
    versions = ['Python 2.7', 'Python 3.2']

    Activity

    1. GhislainHivon commented on Apr 24, 2013

      @GhislainHivon
      GhislainHivonmannequin
      on Apr 24, 2013
      MannequinAuthor
      More actions

      When sniffing the dialect of a file created with the csv module with dialect=csv.excel_tab and one of the row contain a quote ("), the delimiter is set to ' ' instead of '\t'.

    2. GhislainHivon
      added
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Apr 24, 2013
    3. AntoonPardon commented on Mar 25, 2014

      @AntoonPardon
      AntoonPardonmannequin
      on Mar 25, 2014
      Mannequin
      More actions

      I had a look at this and have the following remarks.

      1. the file csv_sniffing_excel_tab.py no longer works with python 3.3. It now produces the folowing traceback:
      Traceback (most recent call last):
        File "csv_sniffing_excel_tab.py", line 36, in <module>
          create_file()
        File "csv_sniffing_excel_tab.py", line 23, in create_file
          writer.writerows(test_data)
      TypeError: 'str' does not support the buffer interface
      1. The problem seems to be in the _guess_quote_and_delimiter method. If you always call _guess_delimiter, the sniffer give the correct result.

      2. As far as I understand the problem is the first regular expression:
        (?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)

      Now if we have a line as the following

      273:MVREGR1:ByEuPo:"Baryton ""Euphonium"" populaire"

      The delim group will match the space, the space group will match nothing the quote group will match " the non-group pattern will match "Euphonium" followed by the quote group matching " again and the delim group matching the space.

      And so we get the wrong delimiter.

    4. AntoonPardon commented on Mar 28, 2014

      @AntoonPardon
      AntoonPardonmannequin
      on Mar 28, 2014
      Mannequin
      More actions

      I included a patch (against 2.7) that seems to make the test work.

      The patch prohibits the delim group to match a space.

    5. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    6. serhiy-storchaka
      added this to CSV issues 📊on May 19, 2022
    7. pradeepkumarai commented on Feb 23, 2023

      @pradeepkumarai
      pradeepkumarai
      on Feb 23, 2023
      More actions

      I included a patch (against 2.7) that seems to make the test work.

      The patch prohibits the delim group to match a space.

    8. arhadthedev
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on Feb 25, 2023
    9. serhiy-storchaka
      self-assigned this
      on Jan 9, 2024
    10. serhiy-storchaka
      closed this as completedin #153694on Jul 21, 2026
    11. github-project-automation
      moved this to Done in CSV issues 📊on Jul 21, 2026
    12. serhiy-storchaka
      reopened this on Jul 21, 2026
    13. serhiy-storchaka
      added
      3.13only security fixesonly security fixes
      3.14bugs and security fixesbugs and security fixes
      3.15bugs and security fixesbugs and security fixes
      on Jul 21, 2026
    14. serhiy-storchaka commented on Jul 21, 2026

      @serhiy-storchaka
      serhiy-storchaka
      on Jul 21, 2026
      Member
      More actions

      Fixed in 3.16 by the csv.Sniffer rewrite (gh-83273). The old code counted every character adjacent to a quoted run and chose the most frequent one, so spaces around quotes inside fields could outnumber the real delimiter.

      The file from the original report is a Python 2 script, but the bug is still reproducible on 3.13 and 3.15:

      import csv, io
      rows = [['alpha', 'he said "hi" and "bye" then'],
              ['beta', 'she said "yes" or "no" maybe'],
              ['gamma', 'we said "up" and "down" too']]
      buf = io.StringIO()
      csv.writer(buf, dialect=csv.excel_tab).writerows(rows)
      print(repr(csv.Sniffer().sniff(buf.getvalue()).delimiter))  # ' ' instead of '\t'

      A targeted fix for the maintenance branches is welcome.

    15. serhiy-storchaka
      removed their assignment
      on Jul 21, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs 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

      • CSV issues 📊
        Status
        Done
        Show more project fields

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.