Skip to content

Commit c2cb113

Browse files
authored
Merge pull request #90 from fish-shop/harden-action
Harden action handling of untrusted inputs
2 parents c7ed2fd + 4bf35d5 commit c2cb113

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ jobs:
4545
continue-on-error: true
4646
uses: ./
4747
with:
48-
pattern: valid-syntax.fish
48+
patterns: valid-syntax.fish
4949
- name: Syntax check invalid fish file
5050
id: check-invalid-file
5151
continue-on-error: true
5252
uses: ./
5353
with:
54-
pattern: invalid-syntax.fish
54+
patterns: invalid-syntax.fish
5555
- name: Check outcomes
5656
run: |
5757
exit_code=0

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ Add a suitable `uses` step to your GitHub [workflow](https://docs.github.com/en/
2525
uses: fish-shop/syntax-check@v1
2626
```
2727
28-
By default, all files under `$GITHUB_WORKSPACE` with a `.fish` file extension are checked. To specify a different file pattern to match against, provide a value for the `pattern` input. For example, to check all `.fish` files starting in the `src` directory and descending into subdirectories:
28+
By default, all files under `$GITHUB_WORKSPACE` with a `.fish` file extension are checked. To override the default behaviour, provide one or more space-seperated pattern values to the `patterns` input. For example, to check all `.fish` files starting in the `src` directory and descending into subdirectories:
2929

3030
```yaml
3131
- name: Syntax check
3232
uses: fish-shop/syntax-check@v1
3333
with:
34-
pattern: src/**.fish
34+
patterns: src/**.fish
3535
```
3636

37-
Multiple space-separated `pattern` values are supported and can include [wildcards](https://fishshell.com/docs/current/language.html#expand-wildcard) and [brace expansion](https://fishshell.com/docs/current/language.html?highlight=brace+expansion#brace-expansion):
37+
Each pattern value may include [wildcards](https://fishshell.com/docs/current/language.html#expand-wildcard) and/or [brace expansion](https://fishshell.com/docs/current/language.html?highlight=brace+expansion#brace-expansion):
3838

3939
```yaml
4040
- name: Syntax check
4141
uses: fish-shop/syntax-check@v1
4242
with:
43-
pattern: init.fish functions/**.fish {conf.d,completions}/**.fish tests/???-*.fish
43+
patterns: init.fish functions/**.fish {conf.d,completions}/**.fish tests/???-*.fish
4444
```
4545

4646
## Action versions

action.yml

+26-16
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,43 @@ branding:
44
icon: 'check'
55
color: 'green'
66
inputs:
7-
pattern:
8-
description: 'File name pattern'
7+
patterns:
8+
description: 'File patterns to match against when running syntax checks'
99
required: false
1010
default: '**.fish'
1111
runs:
1212
using: "composite"
1313
steps:
14-
- run: |
14+
- name: Syntax check fish shell files
15+
env:
16+
PATTERNS: ${{ inputs.patterns }}
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 -- " " $PATTERNS)
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)