The implementation of utils.str2dict fails to convert a dict with more than 2 elements
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
neutron |
Fix Released
|
Medium
|
Jianing Yang |
Bug Description
from neutron.common import utils
print utils.str2dict(
returns
{'inside_addr': '10.0.1.2', 'inside_port': '22,outside_
expected value should be
{'outside_port': '2222', 'inside_addr': '10.0.1.2', 'protocol': 'tcp', 'inside_port': '22', 'outside_addr': '172.16.0.1'}
The reason is that in the third line of the implementation below, string.split(',', 1) only splits out two key-value pairs.
quote from neutron/
def str2dict(string):
res_dict = {}
for keyvalue in string.split(',', 1):
(key, value) = keyvalue.split('=', 1)
return res_dict
a quick fix might be remove ",1" from string.split. But it turns out that str2dict/dict2str may also fail when input values containing characters like '=' or ','. A better fix might be using json encode/decode to deal with it.
Changed in neutron: | |
assignee: | nobody → Jianing YANG (jianingy) |
Changed in neutron: | |
status: | Incomplete → In Progress |
Changed in neutron: | |
milestone: | none → icehouse-2 |
importance: | Undecided → Medium |
Changed in neutron: | |
status: | Fix Committed → Fix Released |
Changed in neutron: | |
milestone: | icehouse-2 → 2014.1 |
Fix proposed to branch: master /review. openstack. org/60195
Review: https:/