-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-skip: improved shell expression parsing (#3514)
A minor improvement over the previous string contents check.
- Loading branch information
1 parent
ae42b03
commit 50b4a20
Showing
2 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package inputgraph | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_containsShellExpr(t *testing.T) { | ||
cases := []struct { | ||
desc string | ||
val string | ||
want bool | ||
}{ | ||
{ | ||
desc: "single", | ||
val: "$(echo 'hello')", | ||
want: true, | ||
}, | ||
{ | ||
desc: "nested", | ||
val: "$(echo -n $(cat /tmp/x))", | ||
want: true, | ||
}, | ||
{ | ||
desc: "invalid 1", | ||
val: "$($()", | ||
want: false, | ||
}, | ||
{ | ||
desc: "invalid 2", | ||
val: ")$(", | ||
want: false, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.desc, func(t *testing.T) { | ||
got := containsShellExpr(c.val) | ||
require.Equal(t, c.want, got) | ||
}) | ||
} | ||
} |