#1470 closed defect (fixed)

tahoe.cfg with UTF-8 BOM should be accepted

Reported by: davidsarah Owned by: davidsarah
Priority: major Milestone: 1.9.2
Component: code Version: 1.8.2
Keywords: unicode config reviewed Cc:
Launchpad Bug:

Description (last modified by davidsarah)

tahoe.cfg is supposed to be encoded in UTF-8. Most editors on Windows save UTF-8 files with an initial Byte Order Mark, but that causes an error on starting the node:

C:\tahoe\furry>bin\tahoe start
STARTING 'C:\Documents and Settings\David-Sarah\.tahoe'
Traceback (most recent call last):
[...]
  File "c:\tahoe\furry\src\allmydata\client.py", line 133, in __init__
    node.Node.__init__(self, basedir)
  File "c:\tahoe\furry\src\allmydata\node.py", line 73, in __init__
    self.read_config()
  File "c:\tahoe\furry\src\allmydata\node.py", line 122, in read_config
    self.config.read([os.path.join(self.basedir, "tahoe.cfg")])
  File "C:\Python27\lib\ConfigParser.py", line 297, in read
    self._read(fp, filename)
  File "C:\Python27\lib\ConfigParser.py", line 504, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
ConfigParser.MissingSectionHeaderError: File contains no section headers.
file: C:\Documents and Settings\David-Sarah\.tahoe\tahoe.cfg, line: 1
'\xef\xbb\xbf# -*- mode: conf; coding: utf-8 -*-\n'

Failed to load application: File contains no section headers.
file: C:\Documents and Settings\David-Sarah\.tahoe\tahoe.cfg, line: 1
'\xef\xbb\xbf# -*- mode: conf; coding: utf-8 -*-\n'

This may also apply to other configuration files.

Attachments (2)

fix-1470.darcs.patch (33.5 KB) - added by davidsarah at 2011-08-12T13:30:56Z.
node.py: tolerate a UTF-8 BOM at the start of tahoe.cfg. fixes #1470
test-1470.darcs.patch (33.5 KB) - added by davidsarah at 2011-08-12T13:31:32Z.
test_node.py: test that we tolerate a UTF-8 BOM at the start of tahoe.cfg, and can read UTF-8 option values. refs #1470

Download all attachments as: .zip

Change History (10)

comment:1 Changed at 2011-08-08T14:56:58Z by davidsarah

  • Description modified (diff)
  • Owner changed from somebody to davidsarah
  • Status changed from new to assigned

Changed at 2011-08-12T13:30:56Z by davidsarah

node.py: tolerate a UTF-8 BOM at the start of tahoe.cfg. fixes #1470

Changed at 2011-08-12T13:31:32Z by davidsarah

test_node.py: test that we tolerate a UTF-8 BOM at the start of tahoe.cfg, and can read UTF-8 option values. refs #1470

comment:2 Changed at 2011-08-12T13:36:02Z by davidsarah

  • Keywords review-needed added
  • Owner davidsarah deleted
  • Status changed from assigned to new

comment:3 follow-up: Changed at 2011-08-14T03:33:12Z by zooko

  • Keywords reviewed added; review-needed removed
  • Owner set to davidsarah

I reviewed these patches and give them +1, although I wonder if it was intentional that it changes the behavior in the case that tahoe.cfg doesn't exist.

Last edited at 2011-08-14T03:46:49Z by zooko (previous) (diff)

comment:4 in reply to: ↑ 3 Changed at 2011-08-14T03:50:10Z by davidsarah

Replying to zooko:

I reviewed these patches and give them +1, although I wonder if it was intentional that it changes the [behaviour] in the case that tahoe.cfg doesn't exist.

It doesn't change the behaviour in that case. SafeConfigParser.read is documented to have no effect if the file doesn't exist:

Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ConfigParser import SafeConfigParser
>>> c = SafeConfigParser()
>>> import os
>>> os.path.exists('nonexistent')
False
>>> c.read(['nonexistent'])
[]
>>> c.sections()
[]

Perhaps we should refuse to start in that case, but currently we just use the defaults for all options.

comment:5 Changed at 2011-08-15T04:25:52Z by davidsarah

  • Milestone changed from soon to 1.10.0

comment:6 Changed at 2012-04-01T00:47:20Z by davidsarah

  • Milestone changed from 1.11.0 to 1.9.2
  • Status changed from new to assigned

comment:7 Changed at 2012-04-01T01:11:46Z by david-sarah@…

  • Resolution set to fixed
  • Status changed from assigned to closed

In ba0df239273f3b52:

node.py: tolerate a UTF-8 BOM at the start of tahoe.cfg. fixes #1470

comment:8 Changed at 2012-04-01T01:11:47Z by david-sarah@…

In 972beffb258d76ea:

test_node.py: test that we tolerate a UTF-8 BOM at the start of tahoe.cfg, and can read UTF-8 option values. refs #1470

Note: See TracTickets for help on using tickets.