From 9093edea28ec472f5202bf864592d320b5d07748 Mon Sep 17 00:00:00 2001 From: aad1tyaaaaa Date: Fri, 27 Nov 2026 21:42:06 +0530 Subject: [PATCH 1/2] Fix str2dicts mangling lines that have no value str.find returns -1, not 0, when there is no space, so the check never skipped such lines and "vnc" became {"vn": "vnc"}. --- CHANGES.rst | 6 ++++++ libcloud/test/compute/test_cloudsigma_v1_0.py | 4 ++++ libcloud/utils/misc.py | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 048d163435..529e8155e1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -36,6 +36,12 @@ 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. + [@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] From 0c3130357f95fef5b23875e872aa84518bf5f785 Mon Sep 17 00:00:00 2001 From: aad1tyaaaaa Date: Fri, 27 Nov 2026 22:01:40 +0530 Subject: [PATCH 2/2] Add the PR number to the changelog entry --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 529e8155e1..5aa43c8bc8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -40,6 +40,7 @@ Common 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