diff --git a/CHANGES.rst b/CHANGES.rst index 048d163435..5aa43c8bc8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -36,6 +36,13 @@ Common (#2152) [Miguel Caballer - @micafer] +- [Utils] Fix ``str2dicts`` turning a line without a value, such as ``vnc``, + into a bogus ``{"vn": "vnc"}`` entry. The check for a missing space compared + the ``str.find`` result against 0 instead of -1. Such lines are now skipped + as intended. This affects responses parsed by the CloudSigma 1.0 driver. + (#2246) + [@aad1tyaaaaa] + - [Utils] Fix ``is_valid_ip_address`` raising ``ValueError`` instead of returning ``False`` for an address containing an embedded null byte (e.g. ``"1.2.3.4\x00"``). ``socket.inet_pton`` raises ``ValueError`` rather diff --git a/libcloud/test/compute/test_cloudsigma_v1_0.py b/libcloud/test/compute/test_cloudsigma_v1_0.py index a0deb3a664..f5024a1f90 100644 --- a/libcloud/test/compute/test_cloudsigma_v1_0.py +++ b/libcloud/test/compute/test_cloudsigma_v1_0.py @@ -115,6 +115,10 @@ def test_str2dicts(self): result = str2dicts(string) self.assertEqual(len(result), 2) + def test_str2dicts_skips_lines_without_value(self): + result = str2dicts("cpu 1100\nvnc\nmem 640") + self.assertEqual(result, [{"cpu": "1100", "mem": "640"}]) + def test_str2list(self): string = "ip 1.2.3.4\nip 1.2.3.5\nip 1.2.3.6" result = str2list(string) diff --git a/libcloud/utils/misc.py b/libcloud/utils/misc.py index 67e885c4bd..a8e1d9131f 100644 --- a/libcloud/utils/misc.py +++ b/libcloud/utils/misc.py @@ -140,7 +140,7 @@ def str2dicts(data): whitespace = line.find(" ") - if not whitespace: + if whitespace == -1: continue key = line[0:whitespace]