Skip to content

A self-hosted dashboard that puts all your feeds in one place

Change environment variables behavior

Svilen Markov1fe7f61ec87e
diff --git a/internal/widget/fields.go b/internal/widget/fields.go
index 9ae1eda..91e7671 100644
--- a/internal/widget/fields.go
+++ b/internal/widget/fields.go
@@ -13,7 +13,7 @@ import (
)
var HSLColorPattern = regexp.MustCompile(`^(?:hsla?\()?(\d{1,3})(?: |,)+(\d{1,3})%?(?: |,)+(\d{1,3})%?\)?$`)
-var EnvFieldPattern = regexp.MustCompile(`^\${([A-Z_]+)}$`)
+var EnvFieldPattern = regexp.MustCompile(`(^|.)\$\{([A-Z_]+)\}`)
const (
HSLHueMax = 360
@@ -133,21 +133,42 @@ func (f *OptionalEnvString) UnmarshalYAML(node *yaml.Node) error {
return err
}
- matches := EnvFieldPattern.FindStringSubmatch(value)
+ replaced := EnvFieldPattern.ReplaceAllStringFunc(value, func(whole string) string {
+ if err != nil {
+ return ""
+ }
- if len(matches) != 2 {
- *f = OptionalEnvString(value)
+ groups := EnvFieldPattern.FindStringSubmatch(whole)
- return nil
- }
+ if len(groups) != 3 {
+ return whole
+ }
+
+ prefix, key := groups[1], groups[2]
+
+ if prefix == `\` {
+ if len(whole) >= 2 {
+ return whole[1:]
+ } else {
+ return ""
+ }
+ }
+
+ value, found := os.LookupEnv(key)
- value, found := os.LookupEnv(matches[1])
+ if !found {
+ err = fmt.Errorf("environment variable %s not found", key)
+ return ""
+ }
- if !found {
- return fmt.Errorf("environment variable %s not found", matches[1])
+ return prefix + value
+ })
+
+ if err != nil {
+ return err
}
- *f = OptionalEnvString(value)
+ *f = OptionalEnvString(replaced)
return nil
}