Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

Commit b353d27

Browse files
author
Lorenz Kästle
committed
Change powershell array parsing
1 parent 03f5518 commit b353d27

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

powershell.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,23 @@ func BuildPowershellType(value string) interface{} {
7474
// Examples:
7575
// @() -> []string{}
7676
// @('abc') -> []string{"abc"}
77-
// @('abc','def') -> []string{"abc","def}
77+
// @('abc','def') -> []string{"abc","def"}
7878
//
7979
func ConvertPowershellArray(value string) []string {
80-
value = reArrayWrap.ReplaceAllString(value, "")
81-
82-
if value == "" {
80+
if value == "@()" {
8381
return []string{}
84-
} else {
85-
return reArraySplit.Split(value, -1)
8682
}
83+
84+
// strip array beginning and end
85+
value = value[3 : len(value)-2]
86+
87+
tmp := strings.Split(value, ",")
88+
89+
for i := range tmp {
90+
tmp[i] = strings.Trim(tmp[i], `"`)
91+
tmp[i] = strings.Trim(tmp[i], `'`)
92+
}
93+
return tmp
8794
}
8895

8996
// ParsePowershellTryCatch parses the actual command from a try/catch PowerShell code snippet.

0 commit comments

Comments
 (0)