a8m / envsubst

Environment variables substitution for Go
MIT License
747 stars 83 forks source link

Default values starting with - (dash/minus sign) do not work #41

Closed neiser closed 1 year ago

neiser commented 1 year ago

Given the reproducer

package main

import (
    "fmt"
    "github.com/a8m/envsubst"
)

func main() {
    out1, err := envsubst.StringRestricted("value is '${not_there:--1}', should be '-1'", true, true)
    if err != nil {
        panic(err)
    }
    fmt.Println(out1)

    // preceding one whitespace is a workaround?
    out2, err := envsubst.StringRestricted("value is '${not_there:- -1}', should be ' -1'", true, true)
    if err != nil {
        panic(err)
    }
    fmt.Println(out2)
}

Output:

value is '1', should be '-1'
value is ' -1', should be ' -1'

I'd like to use -1 as a default string for variable which might be empty or unset. All leading - seems to be stripped unless there's preceding whitespace (which is a workaround for my use case, but might be undesirable in other cases).

My interpretation of the docs say it should work, do you agree? Is this a bug?