Skip to content

Commit

Permalink
Allow results to contain underscores
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bobcatfish authored and tekton-robot committed Apr 23, 2020
1 parent 7653dd1 commit fc2bf79
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/apis/pipeline/v1beta1/resultref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/pipeline/v1beta1/resultref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit fc2bf79

Please sign in to comment.