summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorY.Horie <u5.horie@gmail.com>2023-01-17 20:57:42 +0900
committerGitHub <noreply@github.com>2023-01-17 06:57:42 -0500
commit62e8b21724b0734ceb7879d740902eb3772d34b2 (patch)
treea24d9148bf9127456320f1a0c5432bdb86f602d0 /caddyconfig
parent223cbe3d0b50487117c785f0755bb80a9ee65010 (diff)
chore: Fix caddyfile.replaceEnvVars return (#5311)
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/caddyfile/parse.go14
-rw-r--r--caddyconfig/caddyfile/parse_test.go5
2 files changed, 4 insertions, 15 deletions
diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go
index 2c2da0f..82c515b 100644
--- a/caddyconfig/caddyfile/parse.go
+++ b/caddyconfig/caddyfile/parse.go
@@ -61,20 +61,12 @@ func Parse(filename string, input []byte) ([]ServerBlock, error) {
// It returns all the tokens from the input, unstructured
// and in order. It may mutate input as it expands env vars.
func allTokens(filename string, input []byte) ([]Token, error) {
- inputCopy, err := replaceEnvVars(input)
- if err != nil {
- return nil, err
- }
- tokens, err := Tokenize(inputCopy, filename)
- if err != nil {
- return nil, err
- }
- return tokens, nil
+ return Tokenize(replaceEnvVars(input), filename)
}
// replaceEnvVars replaces all occurrences of environment variables.
// It mutates the underlying array and returns the updated slice.
-func replaceEnvVars(input []byte) ([]byte, error) {
+func replaceEnvVars(input []byte) []byte {
var offset int
for {
begin := bytes.Index(input[offset:], spanOpen)
@@ -115,7 +107,7 @@ func replaceEnvVars(input []byte) ([]byte, error) {
// continue at the end of the replacement
offset = begin + len(envVarBytes)
}
- return input, nil
+ return input
}
type parser struct {
diff --git a/caddyconfig/caddyfile/parse_test.go b/caddyconfig/caddyfile/parse_test.go
index c3f6fa6..e3eff56 100644
--- a/caddyconfig/caddyfile/parse_test.go
+++ b/caddyconfig/caddyfile/parse_test.go
@@ -604,10 +604,7 @@ func TestEnvironmentReplacement(t *testing.T) {
expect: "}{$",
},
} {
- actual, err := replaceEnvVars([]byte(test.input))
- if err != nil {
- t.Fatal(err)
- }
+ actual := replaceEnvVars([]byte(test.input))
if !bytes.Equal(actual, []byte(test.expect)) {
t.Errorf("Test %d: Expected: '%s' but got '%s'", i, test.expect, actual)
}