From fc2bf7906ddae6d45ec9dc7e6b25aadc6f44386d Mon Sep 17 00:00:00 2001 From: Christie Wilson Date: Wed, 22 Apr 2020 15:53:11 -0400 Subject: [PATCH] Allow results to contain underscores When results parsing was implemented, the set of allowed characters wasn't made to match the rest of our substitutions. This duplicates the set of characters though hopefully we can eventually consolidate this logic. I discovered this when trying to use the kaniko task in the catalog https://github.com/tektoncd/catalog/blob/v1beta1/kaniko/kaniko.yaml Part of #2464. --- pkg/apis/pipeline/v1beta1/resultref.go | 7 ++++--- pkg/apis/pipeline/v1beta1/resultref_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pkg/apis/pipeline/v1beta1/resultref.go b/pkg/apis/pipeline/v1beta1/resultref.go index b4f16998a28..478cb62c479 100644 --- a/pkg/apis/pipeline/v1beta1/resultref.go +++ b/pkg/apis/pipeline/v1beta1/resultref.go @@ -33,8 +33,9 @@ const ( // ResultTaskPart Constant used to define the "tasks" part of a pipeline result reference ResultTaskPart = "tasks" // ResultResultPart Constant used to define the "results" part of a pipeline result reference - ResultResultPart = "results" - variableSubstitutionFormat = `\$\([A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\)` + ResultResultPart = "results" + // TODO(#2462) use one regex across all substitutions + variableSubstitutionFormat = `\$\([_a-zA-Z0-9.-]+(\.[_a-zA-Z0-9.-]+)*\)` ) var variableSubstitutionRegex = regexp.MustCompile(variableSubstitutionFormat) @@ -56,7 +57,7 @@ func NewResultRefs(expressions []string) ([]*ResultRef, error) { return resultRefs, nil } -// looksLikeContainsResultRefs attempts to check if param or a pipeline result looks like it contains any +// LooksLikeContainsResultRefs attempts to check if param or a pipeline result looks like it contains any // result references. // This is useful if we want to make sure the param looks like a ResultReference before // performing strict validation diff --git a/pkg/apis/pipeline/v1beta1/resultref_test.go b/pkg/apis/pipeline/v1beta1/resultref_test.go index d2b55a1ad23..de488ff75e3 100644 --- a/pkg/apis/pipeline/v1beta1/resultref_test.go +++ b/pkg/apis/pipeline/v1beta1/resultref_test.go @@ -206,6 +206,23 @@ func TestHasResultReference(t *testing.T) { Result: "sum-result", }, }, + }, { + name: "Test valid expression with underscores", + args: args{ + param: v1beta1.Param{ + Name: "param", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "$(tasks.sum-task.results.sum_result)", + }, + }, + }, + wantRef: []*v1beta1.ResultRef{ + { + PipelineTask: "sum-task", + Result: "sum_result", + }, + }, }, { name: "Test invalid expression: param substitution shouldn't be considered result ref", args: args{