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 ignores in-line comments for lines with semi-colons
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: jahschwa, lukasz.langa
Priority: normal Keywords:

Created on 2016-08-14 02:42 by jahschwa, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ConfigParser_patch.py jahschwa, 2016-08-14 02:42 ConfigParser patch
Messages (2)
msg272641 - (view) Author: Joshua Haas (jahschwa) Date: 2016-08-14 02:42
According to the 2.7 docs at https://docs.python.org/2/library/configparser.html, you can create in-line comments using ";" if it is preceded by white space.

However, if the value of a config option contains a semi-colon, for example "password=my;pass123", then only the first colon will be checked by the parser.

In the config file:
password=my;pass123 ;expires in 2018

Expected value:
my;pass123

Returned value:
my;pass123 ;expires in 2018

This is easily remedied with a while loop, lines 525-529 in the attached patch. Otherwise the docs should be changed to reflect this behavior, but a patch definitely seems more appropriate to me. Python 3.5 gives the expected value when using inline_comment_prefixes=';'.
msg272872 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2016-08-16 18:34
I'm sorry but we can't do anything about this for Python 2.7 anymore. There's a big danger of altering how existing config files in the wild are being parsed, which is why we only broke compatibility once, with the release of Python 3.2. Even then, doing it very carefully, we found a few instances of painful parsing differences (.pypirc being the most widely spread example).

So, the fix here is to switch to Python 3 or use the configparser backport available on PyPI.
History
Date User Action Args
2022-04-11 14:58:34adminsetgithub: 71949
2016-08-16 18:34:32lukasz.langasetstatus: open -> closed
2016-08-16 18:34:23lukasz.langasetresolution: wont fix
messages: + msg272872
2016-08-14 02:44:49ned.deilysetnosy: + lukasz.langa
2016-08-14 02:42:48jahschwacreate