summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-06 18:25:43 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-06-07 16:38:57 +0000
commit59d13fb44be2fed00cd673ddf9064a4de500fcb3 (patch)
tree0dd607e0de3bc7b4c308e1e7cc2b7a13029ac8b3
parentfc1503a84ba33dffb7034d4522458facd1178a09 (diff)
downloadbuildstream-59d13fb44be2fed00cd673ddf9064a4de500fcb3.tar.gz
_yaml: Ensure every element passed to list_copy or node_set is a Node
This is to restrict the API to always work with nodes in order to sanitize the API
-rw-r--r--src/buildstream/_yaml.pyx10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index c565fe12e..4e0659f40 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -624,6 +624,9 @@ cdef list __trim_list_provenance(list value):
cpdef void node_set(Node node, object key, object value, list indices=None) except *:
cdef int idx
+ if type(value) is list:
+ value = __new_node_from_list(value)
+
if indices:
node = <Node> (<dict> node.value)[key]
key = indices.pop()
@@ -1176,11 +1179,10 @@ cpdef Node node_copy(Node source):
# Internal function to help node_copy() but for lists.
cdef Node _list_copy(Node source):
cdef list copy = []
+ cdef Node item
+
for item in source.value:
- if type(item) is Node:
- item_type = type(item.value)
- else:
- item_type = type(item)
+ item_type = type(item.value)
if item_type is dict:
copy.append(node_copy(item))