From aeadec7239b0464af1c3c5df9334648db457cdc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Kivim=C3=A4ki?= Date: Mon, 5 Feb 2024 09:34:04 +0200 Subject: [PATCH] fix(survey): avoid infinite loop if first variable is skipped --- pkg/ui/survey/survey.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/ui/survey/survey.go b/pkg/ui/survey/survey.go index 1d0eb4e0..58908b93 100644 --- a/pkg/ui/survey/survey.go +++ b/pkg/ui/survey/survey.go @@ -144,21 +144,23 @@ func (m SurveyModel) Values() recipe.VariableValues { } func (m *SurveyModel) createNextPrompt() (prompt.Model, error) { - if len(m.prompts) > 0 { - m.cursor++ - } - if m.cursor >= len(m.variables) { return nil, nil } - if p, err := m.createPrompt(m.variables[m.cursor]); err != nil { + p, err := m.createPrompt(m.variables[m.cursor]) + if err != nil { return nil, err - } else if p == nil { + } + + m.cursor++ + + // Skip the prompt if it should be skipped (e.g. because of 'if' condition) + if p == nil { return m.createNextPrompt() - } else { - return p, nil } + + return p, nil } // createPrompt creates a prompt for the given variable. Returns nil if the variable should be skipped.