summaryrefslogtreecommitdiff
path: root/buildstream/_yaml.py
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-05 21:26:12 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-08 17:03:59 +0900
commit1405bbb9018550223f8f75ae705afe2a160bc42b (patch)
tree2e8b12c7385c651087f52f25a08b919ce7bc6b8a /buildstream/_yaml.py
parent62da31935c90c93d41dd778a3b667490cd2287ea (diff)
downloadbuildstream-1405bbb9018550223f8f75ae705afe2a160bc42b.tar.gz
_yaml.py: Dont blindly coerse strings to bool in _yaml.node_get()
This leads to True booleans being evaluated for any string that is not None, even when a string value is "False" or "false". Instead, handle only "True", "true", "False" and "false" strings, and raise an error if another string was specified for a boolean value.
Diffstat (limited to 'buildstream/_yaml.py')
-rw-r--r--buildstream/_yaml.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index c408117b4..458fa3e72 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -362,10 +362,18 @@ def node_get(node, expected_type, key, indices=[], default_value=None):
# be able to specify numeric values and convert them to strings,
# but we dont want to try converting dicts/lists
try:
- if not (expected_type == list or
- expected_type == dict or
- isinstance(value, list) or
- isinstance(value, dict)):
+ if (expected_type == bool and isinstance(value, str)):
+ # Dont coerce booleans to string, this makes "False" strings evaluate to True
+ if value == 'true' or value == 'True':
+ value = True
+ elif value == 'false' or value == 'False':
+ value = False
+ else:
+ raise ValueError()
+ elif not (expected_type == list or
+ expected_type == dict or
+ isinstance(value, list) or
+ isinstance(value, dict)):
value = expected_type(value)
else:
raise ValueError()