From 6b1010ad07f4a451a778191c41e23ac2c8cfd53e Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 21 Apr 2023 14:45:38 +0800 Subject: [PATCH] Fix potential panic caused by nil `Step` (#48) ```yml jobs: job1: steps: - run: echo HelloWorld - # empty step ``` If a job contains an empty step, `Job.Steps` will have a nil element and will cause panic when calling `Step.String()`. See [the code of gitea](https://github.com/go-gitea/gitea/blob/948a9ee5e83586354461e2a0e5cdf00e0513e89d/models/actions/task.go#L300-L301) Reviewed-on: https://gitea.com/gitea/act/pulls/48 Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- pkg/jobparser/model.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/jobparser/model.go b/pkg/jobparser/model.go index 8e1d7bd..4cbdc6d 100644 --- a/pkg/jobparser/model.go +++ b/pkg/jobparser/model.go @@ -143,6 +143,9 @@ type Step struct { // String gets the name of step func (s *Step) String() string { + if s == nil { + return "" + } return (&model.Step{ ID: s.ID, Name: s.Name,