mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
Fixes #14590: ConfigParser doesn't strip inline comment when delimiter occurs
earlier without preceding space.
This commit is contained in:
parent
d94adb7367
commit
cba243215e
2 changed files with 51 additions and 6 deletions
|
@ -993,18 +993,26 @@ class RawConfigParser(MutableMapping):
|
|||
indent_level = 0
|
||||
e = None # None, or an exception
|
||||
for lineno, line in enumerate(fp, start=1):
|
||||
comment_start = None
|
||||
comment_start = sys.maxsize
|
||||
# strip inline comments
|
||||
for prefix in self._inline_comment_prefixes:
|
||||
index = line.find(prefix)
|
||||
if index == 0 or (index > 0 and line[index-1].isspace()):
|
||||
comment_start = index
|
||||
break
|
||||
inline_prefixes = {p: -1 for p in self._inline_comment_prefixes}
|
||||
while comment_start == sys.maxsize and inline_prefixes:
|
||||
next_prefixes = {}
|
||||
for prefix, index in inline_prefixes.items():
|
||||
index = line.find(prefix, index+1)
|
||||
if index == -1:
|
||||
continue
|
||||
next_prefixes[prefix] = index
|
||||
if index == 0 or (index > 0 and line[index-1].isspace()):
|
||||
comment_start = min(comment_start, index)
|
||||
inline_prefixes = next_prefixes
|
||||
# strip full line comments
|
||||
for prefix in self._comment_prefixes:
|
||||
if line.strip().startswith(prefix):
|
||||
comment_start = 0
|
||||
break
|
||||
if comment_start == sys.maxsize:
|
||||
comment_start = None
|
||||
value = line[:comment_start].strip()
|
||||
if not value:
|
||||
if self._empty_lines_in_values:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue