Skip to content

Commit 5c2f0e4

Browse files
committed
refactor some code
1 parent 78b7893 commit 5c2f0e4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

dsc_lib/src/parser/expressions.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,13 @@ impl Expression {
146146
if !object.contains_key(member) {
147147
return Err(DscError::Parser(t!("parser.expression.memberNameNotFound", member = member).to_string()));
148148
}
149-
if is_secure {
150-
// if the original value was a secure value, we need to convert the member value back to secure
151-
value = convert_to_secure(&object[member]);
152-
} else {
153-
value = object[member].clone();
154-
}
149+
value = convert_to_secure(&object[member]);
155150
} else {
156151
return Err(DscError::Parser(t!("parser.expression.accessOnNonObject").to_string()));
157152
}
158153
},
159154
Accessor::Index(index_value) => {
160-
index = index_value.clone();
155+
index = convert_to_secure(index_value);
161156
},
162157
Accessor::IndexExpression(expression) => {
163158
index = expression.invoke(function_dispatcher, context)?;
@@ -174,7 +169,7 @@ impl Expression {
174169
if index >= array.len() {
175170
return Err(DscError::Parser(t!("parser.expression.indexOutOfBounds").to_string()));
176171
}
177-
value = array[index].clone();
172+
value = convert_to_secure(&array[index]);
178173
} else {
179174
return Err(DscError::Parser(t!("parser.expression.indexOnNonArray").to_string()));
180175
}
@@ -190,6 +185,10 @@ impl Expression {
190185
}
191186

192187
fn convert_to_secure(value: &Value) -> Value {
188+
if !is_secure_value(value) {
189+
return value.clone();
190+
}
191+
193192
if let Some(string) = value.as_str() {
194193
let secure_string = crate::configure::parameters::SecureString {
195194
secure_string: string.to_string(),

0 commit comments

Comments
 (0)