You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a foreach-object loop (@(...) | % {...}) is anywhere preceded by a switch statement in a .pode file, the first element of that loop will become null. This does not affect foreach statement loops.
Steps To Reproduce
Steps to reproduce the behavior:
Create the following pode file "test.pode":
$(
switch (1) {
default {}
}
foreach ( $xin@(1,2,3,4) ) {
if ($x-eq$null) {
write-warning"X item was null!"
} else {
write-host"X looking at $x"
}
}
write-host'---'@(1,2,3,4) |ForEach-Object {
if ($_-eq$null) {
write-warning"item was null!"
} else {
write-host"looking at $_"
}
}
)
Run the following Pode server in the same directory:
X looking at 1
X looking at 2
X looking at 3
X looking at 4
---
WARNING: item was null!
looking at 2
looking at 3
looking at 4
Lines starting with X come from the foreach statement loop, while the ones that don't come from the foreach-object loop. In the second loop, the first element is null.
Removing/commenting the switch statement, as well as moving it to after the second loop, will print the expected output:
X looking at 1
X looking at 2
X looking at 3
X looking at 4
---
looking at 1
looking at 2
looking at 3
looking at 4
Expected Behavior
The first element of the foreach-object loop should be accessible like normal.
Platform
OS: Linux, Debian 12
Browser: Firefox 135
Versions:
Pode: Pode 2.12.0 (via PS Gallery)
PowerShell: 7.5.0
Notes
While writing this test case, I noticed that replacing the single quotes with double quotes in the line write-host '---' throws errors aswell:
Describe the Bug
When a foreach-object loop (
@(...) | % {...}
) is anywhere preceded by a switch statement in a .pode file, the first element of that loop will become null. This does not affect foreach statement loops.Steps To Reproduce
Steps to reproduce the behavior:
Lines starting with X come from the foreach statement loop, while the ones that don't come from the foreach-object loop. In the second loop, the first element is null.
Removing/commenting the switch statement, as well as moving it to after the second loop, will print the expected output:
Expected Behavior
The first element of the foreach-object loop should be accessible like normal.
Platform
Notes
While writing this test case, I noticed that replacing the single quotes with double quotes in the line
write-host '---'
throws errors aswell:The text was updated successfully, but these errors were encountered: