Skip to content

Commit a19c780

Browse files
committed
Fix host splitting
The second parameter to `str.split()` is the maximum number of splits to do, which means the list will have at most that many plus one elements. For strings which have more than 2 dots this causes an unintended ValueError. For example: ``` >>> host, vdc, _ = 'host-1.vdc.env'.split('.', 3) >>> host, vdc, _ = 'host-1.vdc.env.computers.gov.uk'.split('.', 3) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: too many values to unpack >>> host, vdc, _ = 'host-1.vdc.env.computers.gov.uk'.split('.', 2) ```
1 parent 58ca6cb commit a19c780

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fabfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def fetch(self):
9696

9797
for host in self.hosts:
9898
try:
99-
name, vdc, _ = host.split('.', 3)
99+
name, vdc, _ = host.split('.', 2)
100100
except ValueError:
101101
warn("discarding badly formatted hostname '{0}'".format(host))
102102
continue

0 commit comments

Comments
 (0)