Skip to content

Commit 91e6817

Browse files
committed
Harden action with escaping and intermediate env var
1 parent c7ed2fd commit 91e6817

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

action.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,36 @@ inputs:
1111
runs:
1212
using: "composite"
1313
steps:
14-
- run: |
14+
- name: Syntax check fish shell files
15+
env:
16+
PATTERN: ${{ inputs.pattern }}
17+
run: |
1518
set -gx TERM xterm-256color
1619
1720
set -l passes 0
1821
set -l failures 0
1922
20-
for file in ${{ inputs.pattern }}
21-
echo -n " "
22-
set output (fish --no-execute $file 2>&1)
23-
if test $status -ne 0
24-
set_color red; and echo -n "✖"; and set_color normal
25-
echo " $file"
26-
for line in (string split $output)
27-
echo " $line"
23+
for pattern in (string split --no-empty -- " " $PATTERN)
24+
set -l escaped (string escape --style=script --no-quoted -- $pattern)
25+
set -l escaped (string replace -r -a -- '\\\([?*{}])' '$1' $escaped)
26+
27+
eval set -l files $escaped
28+
29+
for file in $files
30+
echo -n " "
31+
set output (fish --no-execute $file 2>&1)
32+
if test $status -ne 0
33+
set_color red; and echo -n "✖"; and set_color normal
34+
echo " $file"
35+
for line in (string split -- $output)
36+
echo " $line"
37+
end
38+
set failures (math $failures + 1)
39+
else
40+
set_color green; and echo -n "✔"; and set_color normal
41+
echo " $file"
42+
set passes (math $passes + 1)
2843
end
29-
set failures (math $failures + 1)
30-
else
31-
set_color green; and echo -n "✔"; and set_color normal
32-
echo " $file"
33-
set passes (math $passes + 1)
3444
end
3545
end
3646

0 commit comments

Comments
 (0)