From 981756b45699d376a9706554be4f6b406c4552eb Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 24 Oct 2021 15:20:27 -0700 Subject: [PATCH] Support escaping dollar signs in the YAML config file; closes pterodactyl/panel#3692 --- config/config.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 07b6a74..a75befb 100644 --- a/config/config.go +++ b/config/config.go @@ -457,9 +457,22 @@ func FromFile(path string) error { return err } // Replace environment variables within the configuration file with their - // values from the host system. - b = []byte(os.ExpandEnv(string(b))) - if err := yaml.Unmarshal(b, c); err != nil { + // values from the host system. This function works almost identically to + // the default os.ExpandEnv function, except it supports escaping dollar + // signs in the text if you pass "$$" through. + // + // "some$$foo" -> "some$foo" + // "some$foo" -> "some" (or "someVALUE_OF_FOO" if FOO is defined in env) + // + // @see https://github.com/pterodactyl/panel/issues/3692 + exp := os.Expand(string(b), func(s string) string { + if s == "$" { + return s + } + return os.Getenv(s) + }) + + if err := yaml.Unmarshal([]byte(exp), c); err != nil { return err } // Store this configuration in the global state.