Commit 4f31882e authored by Guido Trotter's avatar Guido Trotter

_SplitKeyVal with no data return an empty dict

If an empty string is passed to _SplitKeyVal, we should return {},
rather than {'': True}. Also test for the correct behavior.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent d1a7d66f
......@@ -259,20 +259,21 @@ def _SplitKeyVal(opt, data):
NO_PREFIX = "no_"
UN_PREFIX = "-"
kv_dict = {}
for elem in data.split(","):
if "=" in elem:
key, val = elem.split("=", 1)
else:
if elem.startswith(NO_PREFIX):
key, val = elem[len(NO_PREFIX):], False
elif elem.startswith(UN_PREFIX):
key, val = elem[len(UN_PREFIX):], None
if data:
for elem in data.split(","):
if "=" in elem:
key, val = elem.split("=", 1)
else:
key, val = elem, True
if key in kv_dict:
raise errors.ParameterError("Duplicate key '%s' in option %s" %
(key, opt))
kv_dict[key] = val
if elem.startswith(NO_PREFIX):
key, val = elem[len(NO_PREFIX):], False
elif elem.startswith(UN_PREFIX):
key, val = elem[len(UN_PREFIX):], None
else:
key, val = elem, True
if key in kv_dict:
raise errors.ParameterError("Duplicate key '%s' in option %s" %
(key, opt))
kv_dict[key] = val
return kv_dict
......
......@@ -75,6 +75,10 @@ class TestSplitKeyVal(unittest.TestCase):
self.failUnlessRaises(ParameterError, cli._SplitKeyVal,
"option", data)
def testEmptyData(self):
"""Test how we handle splitting an empty string"""
self.failUnlessEqual(cli._SplitKeyVal("option", ""), {})
class TestToStream(unittest.TestCase):
"""Thes the ToStream functions"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment