From: Daan De Meyer Date: Mon, 8 Jul 2024 17:41:16 +0000 (+0200) Subject: Fix empty strings for lists and dicts X-Git-Tag: v24~50^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8aefea6923dd049d060eea7e88f9054b674b432e;p=thirdparty%2Fmkosi.git Fix empty strings for lists and dicts Parse functions should return None to pick the default value. Also, we don't get any values at all if unescape=True and the empty string is passed so make sure we handle that case as well. --- diff --git a/mkosi/config.py b/mkosi/config.py index c8fbe5205..eda345539 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -778,18 +778,20 @@ def config_make_list_parser(delimiter: str, if value is None: return [] + # Empty strings reset the list. + if unescape: lex = shlex.shlex(value, posix=True) lex.whitespace_split = True lex.whitespace = f"\n{delimiter}" lex.commenters = "" values = list(lex) + if reset and not values: + return None else: values = value.replace(delimiter, "\n").split("\n") - - # Empty strings reset the list. - if reset and len(values) == 1 and values[0] == "": - return [] + if reset and len(values) == 1 and values[0] == "": + return None return new + [parse(v) for v in values if v] @@ -855,18 +857,20 @@ def config_make_dict_parser(delimiter: str, return new + # Empty strings reset the dict. + if unescape: lex = shlex.shlex(value, posix=True) lex.whitespace_split = True lex.whitespace = f"\n{delimiter}" lex.commenters = "" values = list(lex) + if reset and not values: + return None else: values = value.replace(delimiter, "\n").split("\n") - - # Empty strings reset the dict. - if reset and len(values) == 1 and values[0] == "": - return {} + if reset and len(values) == 1 and values[0] == "": + return None return new | dict(parse(v) for v in values if v)