Fix ResolveEnvVar when path is not set.
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Thu, 18 May 2017 14:47:58 +0000 (16:47 +0200)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Thu, 18 May 2017 14:47:58 +0000 (16:47 +0200)
lib/common/filepath.go

index 42ef82f..4c8c0da 100644 (file)
@@ -24,9 +24,12 @@ func Exists(path string) bool {
 // ResolveEnvVar Resolved environment variable regarding the syntax ${MYVAR}
 // or $MYVAR following by a slash or a backslash
 func ResolveEnvVar(s string) (string, error) {
+       if s == "" {
+               return s, nil
+       }
 
        // Resolved tilde : ~/
-       if s[:2] == "~/" {
+       if len(s) > 2 && s[:2] == "~/" {
                if usr, err := user.Current(); err == nil {
                        s = filepath.Join(usr.HomeDir, s[2:])
                }