From a8777563f19fe5f9f190b96a61b6bab8cdcd58d2 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 12 Jan 2023 12:18:15 +0000 Subject: vyos.util: T4933: informative error for bad colon-separated lines in vyos.util.colon_separated_to_dict (cherry picked from commit fb7f162f61522127ca72adffd6802797b136a99a) --- python/vyos/util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/vyos/util.py b/python/vyos/util.py index 4df046a36..03809fc83 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -349,9 +349,11 @@ def colon_separated_to_dict(data_string, uniquekeys=False): l = l.strip() if l: match = re.match(key_value_re, l) - if match: + if match and (len(match.groups()) == 2): key = match.groups()[0].strip() value = match.groups()[1].strip() + else: + raise ValueError(f"""Line "{l}" could not be parsed a colon-separated pair """, l) if key in data.keys(): if uniquekeys: raise ValueError("Data string has duplicate keys: {0}".format(key)) -- cgit v1.2.3