summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-06 18:25:43 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-06-06 22:44:19 +0100
commitbba475f70f625c75e184de823d8580d5754d2cd6 (patch)
treedfd09ec0f679c42c5afb3168997d809109dd496b
parentaa8ebac66d89b97a6a51a41382fd3f3af5259947 (diff)
downloadbuildstream-bba475f70f625c75e184de823d8580d5754d2cd6.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))