Skip to content

Commit 769f67b

Browse files
authored
Merge pull request #942 from jonjohnsonjr/fail-on-bad-subst
Fail if unknown variable is used in substitution
2 parents 6da8977 + 8ca4acd commit 769f67b

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

pkg/build/pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func validateWith(data map[string]string, inputs map[string]config.Input) (map[s
189189
}
190190

191191
for k, v := range inputs {
192-
if data[k] == "" && v.Default != "" {
192+
if data[k] == "" {
193193
data[k] = v.Default
194194
}
195195

pkg/build/pipeline_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ func Test_mutateStringFromMap(t *testing.T) {
3535
}
3636

3737
input1 := "${{inputs.foo}} ${{inputs.baz-bah-boom}}"
38-
output1, err := util.MutateStringFromMap(keys, input1)
38+
_, err := util.MutateStringFromMap(keys, input1)
3939

40-
require.NoError(t, err)
41-
require.Equal(t, output1, "foo ", "bogus variable substitution not deleted")
40+
require.Error(t, err)
4241
}
4342

4443
func Test_substitutionMap(t *testing.T) {

pkg/build/pipelines/autoconf/configure.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ inputs:
1616
The GNU triplet which describes the build system.
1717
default: ${{host.triplet.gnu}}
1818

19+
opts:
20+
description: |
21+
Options to pass to the ./configure command.
22+
default: ''
23+
1924
pipeline:
2025
- runs: |
2126
cd ${{inputs.dir}}

pkg/cond/subst.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package cond
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"strings"
2021

@@ -30,18 +31,21 @@ func Subst(inputExpr string, lookupFns ...VariableLookupFunction) (string, error
3031

3132
whiteSpace := goparsify.Many(goparsify.Exact(" "))
3233
variableName := goparsify.Chars("a-zA-Z0-9.\\-_")
34+
errs := []error{}
3335
variable := goparsify.Seq("${{", whiteSpace, variableName, whiteSpace, "}}").Map(func(n *goparsify.Result) {
3436
if resolved, err := lookupFn(n.Child[2].Token); err == nil {
3537
n.Token = resolved
3638
n.Result = resolved
3739
} else {
40+
errs = append(errs, err)
3841
n.Token = ""
3942
n.Result = ""
4043
}
4144
})
4245

4346
text := goparsify.Until("${{")
4447
node := goparsify.Any(text, variable)
48+
4549
document := goparsify.Many(node).Map(func(n *goparsify.Result) {
4650
tokens := []string{}
4751
for _, tok := range n.Child {
@@ -55,6 +59,10 @@ func Subst(inputExpr string, lookupFns ...VariableLookupFunction) (string, error
5559
return "", fmt.Errorf("parser error: %w", err)
5660
}
5761

62+
if err := errors.Join(errs...); err != nil {
63+
return "", err
64+
}
65+
5866
if rstr, ok := result.(string); ok {
5967
return rstr, nil
6068
}

0 commit comments

Comments
 (0)