Skip to content

Commit 1d7518e

Browse files
fix: handle quote delimeter for pin actions
1 parent 336876c commit 1d7518e

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

remediation/workflow/pin/pinactions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func PinAction(action, inputYaml string, exemptedActions []string, pinToImmutabl
105105
// - "actions/checkout@v1"" - Matches (quote delimiter)
106106
// - "actions/checkout@v1" - Matches (quote delimiter)
107107
// - "actions/checkout@v1\n" - Matches (newline is considered whitespace \s)
108-
actionRegex := regexp.MustCompile(`(` + regexp.QuoteMeta(action) + `)($|\s|"|')`)
108+
actionRegex := regexp.MustCompile(`((?:["'])?` + regexp.QuoteMeta(action) + `(?:["'])?)($|\s|"|')`)
109109
inputYaml = actionRegex.ReplaceAllString(inputYaml, pinnedAction+"$2")
110110
yamlWithPreviousActionCommentsRemoved, wasModified := removePreviousActionComments(pinnedAction, inputYaml)
111111
if wasModified {

remediation/workflow/pin/pinactions_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ func TestPinActions(t *testing.T) {
295295
{fileName: "immutableaction-1.yml", wantUpdated: true, pinToImmutable: true},
296296
{fileName: "exemptaction.yml", wantUpdated: true, exemptedActions: []string{"actions/checkout", "rohith/*"}, pinToImmutable: true},
297297
{fileName: "donotpintoimmutable.yml", wantUpdated: true, pinToImmutable: false},
298+
{fileName: "invertedcommas.yml", wantUpdated: true, pinToImmutable: false},
298299
}
299300
for _, tt := range tests {
300301
input, err := ioutil.ReadFile(path.Join(inputDirectory, tt.fileName))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "close issue"
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
closeissue:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Close Issue
12+
uses: "peter-evans/close-issue@v1"
13+
with:
14+
issue-number: 1
15+
comment: Auto-closing issue
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "close issue"
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
closeissue:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Close Issue
12+
uses: peter-evans/close-issue@a700eac5bf2a1c7a8cb6da0c13f93ed96fd53dbe # v1.0.3
13+
with:
14+
issue-number: 1
15+
comment: Auto-closing issue

0 commit comments

Comments
 (0)