Skip to content

Commit 58f8cad

Browse files
idsulikndeloof
authored andcommitted
fix(variables): Add number suffix support to the variable extractor
Signed-off-by: Suleiman Dibirov <[email protected]>
1 parent 9d02caa commit 58f8cad

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

template/variables.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ func extractVariable(value interface{}, pattern *regexp.Regexp) ([]Variable, boo
108108
if r >= 'A' && r <= 'Z' {
109109
return false
110110
}
111+
if r >= '0' && r <= '9' {
112+
return false
113+
}
111114
if r == '_' {
112115
return false
113116
}

template/variables_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ func TestExtractVariables(t *testing.T) {
5050
"bar": {Name: "bar"},
5151
},
5252
},
53+
{
54+
name: "variable-without-curly-braces-and-with-number-suffix",
55+
dict: map[string]interface{}{
56+
"foo": "$bar_1",
57+
},
58+
expected: map[string]Variable{
59+
"bar_1": {Name: "bar_1"},
60+
},
61+
},
5362
{
5463
name: "variable",
5564
dict: map[string]interface{}{
@@ -68,6 +77,15 @@ func TestExtractVariables(t *testing.T) {
6877
"bar": {Name: "bar", DefaultValue: "", Required: true},
6978
},
7079
},
80+
{
81+
name: "required-variable-with-number-suffix",
82+
dict: map[string]interface{}{
83+
"foo": "${bar_1?:foo}",
84+
},
85+
expected: map[string]Variable{
86+
"bar_1": {Name: "bar_1", DefaultValue: "", Required: true},
87+
},
88+
},
7189
{
7290
name: "required-variable2",
7391
dict: map[string]interface{}{
@@ -95,6 +113,24 @@ func TestExtractVariables(t *testing.T) {
95113
"bar": {Name: "bar", DefaultValue: "foo"},
96114
},
97115
},
116+
{
117+
name: "default-variable-with-number-suffix",
118+
dict: map[string]interface{}{
119+
"foo": "${bar_1:-foo}",
120+
},
121+
expected: map[string]Variable{
122+
"bar_1": {Name: "bar_1", DefaultValue: "foo"},
123+
},
124+
},
125+
{
126+
name: "default-variable2-with-number-suffix",
127+
dict: map[string]interface{}{
128+
"foo": "${bar_1-foo}",
129+
},
130+
expected: map[string]Variable{
131+
"bar_1": {Name: "bar_1", DefaultValue: "foo"},
132+
},
133+
},
98134
{
99135
name: "multiple-values",
100136
dict: map[string]interface{}{

0 commit comments

Comments
 (0)