Skip to content

Commit

Permalink
fix: placeholders in environement variables (#1018)
Browse files Browse the repository at this point in the history
* Fixes checking the env key instead of the value.

* Adds custom variable test.

---------

Co-authored-by: a.stecher <[email protected]>
  • Loading branch information
AlliBalliBaba and a.stecher authored Sep 4, 2024
1 parent dcf190e commit a4ac4eb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (f *FrankenPHPModule) Provision(ctx caddy.Context) error {
if f.preparedEnv == nil {
f.preparedEnv = frankenphp.PrepareEnv(f.Env)

for e := range f.preparedEnv {
for _, e := range f.preparedEnv {
if needReplacement(e) {
f.preparedEnvNeedsReplacement = true

Expand All @@ -287,7 +287,7 @@ func (f *FrankenPHPModule) Provision(ctx caddy.Context) error {
return nil
}

// needReplacement checks if a string contains placeholdes.
// needReplacement checks if a string contains placeholders.
func needReplacement(s string) bool {
return strings.Contains(s, "{") || strings.Contains(s, "}")
}
Expand Down
34 changes: 34 additions & 0 deletions caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,40 @@ func TestJsonEnv(t *testing.T) {
tester.AssertGetResponse("http://localhost:9080/worker-env.php", http.StatusOK, "bazbar")
}

func TestCustomCaddyVariablesInEnv(t *testing.T) {
tester := caddytest.NewTester(t)
tester.InitServer(`
{
skip_install_trust
admin localhost:2999
http_port 9080
https_port 9443
frankenphp {
worker {
file ../testdata/worker-env.php
num 1
env FOO world
}
}
}
localhost:9080 {
route {
map 1 {my_customvar} {
default "hello "
}
php {
root ../testdata
env FOO {my_customvar}
}
}
}
`, "caddyfile")

tester.AssertGetResponse("http://localhost:9080/worker-env.php", http.StatusOK, "hello world")
}

func TestPHPServerDirective(t *testing.T) {
tester := caddytest.NewTester(t)
tester.InitServer(`
Expand Down

0 comments on commit a4ac4eb

Please sign in to comment.