Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 06:45 UTC
chore: Fix caddyfile.replaceEnvVars return (#5311)
Y.Horie committed
Jan 17, 2023 at 20:57 UTC
62e8b21724b0734ceb7879d740902eb3772d34b2
2 files changed
+4
-15
caddyconfig/caddyfile/parse.go
+3
-11
@@ -61,20 +61,12 @@ func Parse(filename string, input []byte) ([]ServerBlock, error) {
61
// It returns all the tokens from the input, unstructured
62
// and in order. It may mutate input as it expands env vars.
63
func allTokens(filename string, input []byte) ([]Token, error) {
64
- inputCopy, err := replaceEnvVars(input)
65
- if err != nil {
66
- return nil, err
67
- }
68
- tokens, err := Tokenize(inputCopy, filename)
69
- if err != nil {
70
- return nil, err
71
- }
72
- return tokens, nil
64
+ return Tokenize(replaceEnvVars(input), filename)
65
}
66
67
// replaceEnvVars replaces all occurrences of environment variables.
68
// It mutates the underlying array and returns the updated slice.
77
-func replaceEnvVars(input []byte) ([]byte, error) {
69
+func replaceEnvVars(input []byte) []byte {
70
var offset int
71
for {
72
begin := bytes.Index(input[offset:], spanOpen)
@@ -115,7 +107,7 @@ func replaceEnvVars(input []byte) ([]byte, error) {
107
// continue at the end of the replacement
108
offset = begin + len(envVarBytes)
109
}
118
- return input, nil
110
+ return input
111
}
112
113
type parser struct {
caddyconfig/caddyfile/parse_test.go
+1
-4
@@ -604,10 +604,7 @@ func TestEnvironmentReplacement(t *testing.T) {
604
expect: "}{$",
605
},
606
} {
607
- actual, err := replaceEnvVars([]byte(test.input))
608
- if err != nil {
609
- t.Fatal(err)
610
- }
607
+ actual := replaceEnvVars([]byte(test.input))
608
if !bytes.Equal(actual, []byte(test.expect)) {
609
t.Errorf("Test %d: Expected: '%s' but got '%s'", i, test.expect, actual)
610
}