File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,11 @@ Describe 'Expressions tests' {
5
5
It ' Accessors work: <text>' - TestCases @ (
6
6
@ { text = " [parameters('test').hello]" ; expected = ' @{world=there}' }
7
7
@ { text = " [parameters('test').hello.world]" ; expected = ' there' }
8
+ @ { text = " [parameters('test').array[0]]" ; expected = ' one' }
9
+ @ { text = " [parameters('test').array[1][1]]" ; expected = ' three' }
10
+ @ { text = " [parameters('test').objectArray[0].name]" ; expected = ' one' }
11
+ @ { text = " [parameters('test').objectArray[1].value[0]]" ; expected = ' 2' }
12
+ @ { text = " [parameters('test').objectArray[1].value[1].name]" ; expected = ' three' }
8
13
) {
9
14
param ($text , $expected )
10
15
$yaml = @"
Original file line number Diff line number Diff line change @@ -120,20 +120,16 @@ impl Expression {
120
120
for accessor in & self . accessors {
121
121
match accessor {
122
122
Accessor :: Member ( member) => {
123
- if !value. is_object ( ) {
124
- return Err ( DscError :: Parser ( "Member access on non-object value" . to_string ( ) ) ) ;
125
- }
126
123
if let Some ( object) = value. as_object ( ) {
127
124
if !object. contains_key ( member) {
128
125
return Err ( DscError :: Parser ( format ! ( "Member '{member}' not found" ) ) ) ;
129
126
}
130
127
value = object[ member] . clone ( ) ;
128
+ } else {
129
+ return Err ( DscError :: Parser ( "Member access on non-object value" . to_string ( ) ) ) ;
131
130
}
132
131
} ,
133
132
Accessor :: Index ( index) => {
134
- if !value. is_array ( ) {
135
- return Err ( DscError :: Parser ( "Index access on non-array value" . to_string ( ) ) ) ;
136
- }
137
133
if let Some ( array) = value. as_array ( ) {
138
134
if !index. is_number ( ) {
139
135
return Err ( DscError :: Parser ( "Index is not a number" . to_string ( ) ) ) ;
@@ -146,6 +142,8 @@ impl Expression {
146
142
return Err ( DscError :: Parser ( "Index out of bounds" . to_string ( ) ) ) ;
147
143
}
148
144
value = array[ index] . clone ( ) ;
145
+ } else {
146
+ return Err ( DscError :: Parser ( "Index access on non-array value" . to_string ( ) ) ) ;
149
147
}
150
148
} ,
151
149
}
You can’t perform that action at this time.
0 commit comments