configfile: Make getlists return an empty list on empty string. (#6042)

Signed-off-by: Jordan Woyak <jordan.woyak@gmail.com>
This commit is contained in:
Jordan Woyak 2023-02-09 20:41:09 -06:00 committed by GitHub
parent df1137ef75
commit 1e7057e917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -80,11 +80,15 @@ class ConfigWrapper:
def getlists(self, option, default=sentinel, seps=(',',), count=None, def getlists(self, option, default=sentinel, seps=(',',), count=None,
parser=str, note_valid=True): parser=str, note_valid=True):
def lparser(value, pos): def lparser(value, pos):
if len(value.strip()) == 0:
# Return an empty list instead of [''] for empty string
parts = []
else:
parts = [p.strip() for p in value.split(seps[pos])]
if pos: if pos:
# Nested list # Nested list
parts = [p.strip() for p in value.split(seps[pos])]
return tuple([lparser(p, pos - 1) for p in parts if p]) return tuple([lparser(p, pos - 1) for p in parts if p])
res = [parser(p.strip()) for p in value.split(seps[pos])] res = [parser(p) for p in parts]
if count is not None and len(res) != count: if count is not None and len(res) != count:
raise error("Option '%s' in section '%s' must have %d elements" raise error("Option '%s' in section '%s' must have %d elements"
% (option, self.section, count)) % (option, self.section, count))