From 9a89a057368be231b913122e4db281a9fea526c4 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. (cherry picked from commit fc2bf7906ddae6d45ec9dc7e6b25aadc6f44386d) --- 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 c9beb74c063..1c07e8a69ab 100644 --- a/pkg/apis/pipeline/v1beta1/resultref.go +++ b/pkg/apis/pipeline/v1beta1/resultref.go @@ -30,8 +30,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) @@ -53,7 +54,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 d7553c50e21..305bbb83da2 100644 --- a/pkg/apis/pipeline/v1beta1/resultref_test.go +++ b/pkg/apis/pipeline/v1beta1/resultref_test.go @@ -203,6 +203,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{