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?
Given the reproducer
Output:
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?