python / cpython

The Python programming language
https://www.python.org
Other
62.38k stars 29.96k forks source link

ConfigParser.read silently fails if filenames argument is a byte string #75488

Closed cc078fa6-9844-4016-bade-976a9d810ae6 closed 6 years ago

cc078fa6-9844-4016-bade-976a9d810ae6 commented 7 years ago
BPO 31307
Nosy @ambv, @berkerpeksag, @vxgmichel, @DavidCEllis, @Cryvate
PRs
  • python/cpython#3420
  • 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: ```python assignee = None closed_at = created_at = labels = ['3.7', 'type-feature', 'library'] title = 'ConfigParser.read silently fails if filenames argument is a byte string' updated_at = user = 'https://github.com/vxgmichel' ``` bugs.python.org fields: ```python activity = actor = 'berker.peksag' assignee = 'none' closed = True closed_date = closer = 'berker.peksag' components = ['Library (Lib)'] creation = creator = 'vxgmichel' dependencies = [] files = [] hgrepos = [] issue_num = 31307 keywords = [] message_count = 5.0 messages = ['301026', '301149', '301192', '305421', '305422'] nosy_count = 5.0 nosy_names = ['lukasz.langa', 'berker.peksag', 'vxgmichel', 'David Ellis', 'cryvate'] pr_nums = ['3420'] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue31307' versions = ['Python 3.7'] ```

    cc078fa6-9844-4016-bade-976a9d810ae6 commented 7 years ago

    Calling config_parser.read with 'test' is equivalent to:

        config_parser.read(['test'])
    
    while calling `config_parser.read` with `b'test'` is treated as:
    
        config_parser.read([116, 101, 115, 116])

    which means python will try to open the file descriptors 101, 115 and 116.

    I don't know if byte path should be supported, but this is probably not the expected behavior.

    The method code: https://github.com/python/cpython/blob/master/Lib/configparser.py#L678-L702

    ambv commented 7 years ago

    Good catch. Supporting bytes passed as a path is a reasonable request since the builtin open() supports this, too. Go ahead and create a pull request! We only need to modify line 690 to also list bytes.

    3873e664-9d3f-406b-bb16-a4d912ca397a commented 7 years ago

    This is related to the issue I'd brought up previously here so closing this would also close that issue: http://bugs.python.org/issue29627

    I did originally attempt to add support for bytes in PR where I added support for Path-like objects: https://github.com/python/cpython/pull/242 but I was asked to take it back out.

    berkerpeksag commented 6 years ago

    New changeset e314853d57450b2b9523157eebd405289a795a0e by Berker Peksag (Vincent Michel) in branch 'master': bpo-31307: Make ConfigParser.read() accept bytes objects (GH-3420) https://github.com/python/cpython/commit/e314853d57450b2b9523157eebd405289a795a0e

    berkerpeksag commented 6 years ago

    Thanks! I went ahead and merged PR 3420 since Łukasz (the configparser maintainer) has accepted the idea.