This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ConfigParser spaces in keys not read
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: fdrake Nosy List: fdrake, martinthompson, rhettinger
Priority: normal Keywords:

Created on 2002-07-18 08:07 by martinthompson, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (3)
msg11610 - (view) Author: Martin Thompson (martinthompson) Date: 2002-07-18 08:07
ConfigParser will write, but not read keys with spaces in, eg
key with spaces in = 5
 raises a parse exception.

My fix, tested a small amount on one file!:  
Change regexp on Line 390 to
    OPTCRE = re.compile(
        r'(?P<option>[^=:]+?)'      # anything not an = or :, don;t grab the last space, leave for next bit
        r'[ \t]*(?P<vi>[:=])[ \t]*'           # any number of space/tab,
                                              # followed by separator
                                              # (either : or =), followed
                                              # by any # space/tab
        r'(?P<value>.*)$'                     # everything up to eol
        )


msg11611 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-08-18 22:50
Logged In: YES 
user_id=80475

Having spaces in the keys does not conflict with the 
documentation for ConfigParser; however, it is inconsistent 
with RFC 822 (which serves as a style guide):

"""The  field-name must be composed of printable ASCII 
characters  (i.e., characters that  have  values  between  
33.  and  126., decimal, except colon)."""

Still, there are valid use cases.  For instance, Windows 
style directory names are potentially useful as keys, yet 
the names allow internal spaces:

[DirectoryAttributes]
My Documents = Hide
My Pictures = Show

Jeremy, do you think multiword keys are the way to go?  If 
so, re-assign to me for implementation in Python 2.3.
msg11612 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2002-09-27 16:35
Logged In: YES 
user_id=3066

I've relaxed the parsing of keys so that whitespace inside
the key is allowed, but not at the start or end of the key;
that seems a reasonable constraint.  Internal whitespace is
not normalized.

Commited as Lib/ConfigParser.py 1.47 and 1.38.10.4, unit
tests added in Lib/test/test_cfgparser.py 1.14 and 1.9.10.3.
History
Date User Action Args
2022-04-10 16:05:30adminsetgithub: 36909
2002-07-18 08:07:46martinthompsoncreate