Manager: allow backslashes in variables
Windows machines should be able to simply use backslashes.
This commit is contained in:
parent
f82ebea11d
commit
6b4b205c1c
@ -378,15 +378,7 @@ func (c *Conf) constructVariableLookupTableForVars(vars map[string]Variable) {
|
|||||||
// Given a variable 'apps' with value '/path/to/apps',
|
// Given a variable 'apps' with value '/path/to/apps',
|
||||||
// '/path/to/apps/blender' should be remapped to '{apps}/blender'.
|
// '/path/to/apps/blender' should be remapped to '{apps}/blender'.
|
||||||
if variable.IsTwoWay {
|
if variable.IsTwoWay {
|
||||||
if strings.Contains(value.Value, "\\") {
|
value.Value = crosspath.TrimTrailingSep(value.Value)
|
||||||
log.Warn().
|
|
||||||
Str("variable", name).
|
|
||||||
Str("audience", string(value.Audience)).
|
|
||||||
Str("platform", string(value.Platform)).
|
|
||||||
Str("value", value.Value).
|
|
||||||
Msg("Backslash found in variable value. Change paths to use forward slashes instead.")
|
|
||||||
}
|
|
||||||
value.Value = strings.TrimRight(value.Value, "/")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if value.Platform != "" {
|
if value.Platform != "" {
|
||||||
|
@ -149,3 +149,16 @@ func pathSepForPlatform(platform string) string {
|
|||||||
func isPathSep(r rune) bool {
|
func isPathSep(r rune) bool {
|
||||||
return r == '/' || r == '\\'
|
return r == '/' || r == '\\'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TrimTrailingSep removes any trailling path separator.
|
||||||
|
func TrimTrailingSep(path string) string {
|
||||||
|
if path == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
trimmed := strings.TrimRightFunc(path, isPathSep)
|
||||||
|
if trimmed == "" {
|
||||||
|
return string([]rune(path)[0])
|
||||||
|
}
|
||||||
|
return trimmed
|
||||||
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package crosspath
|
package crosspath
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -237,3 +235,35 @@ func TestToPlatform(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTrimTrailingSep(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"empty", args{""}, ""},
|
||||||
|
{"single-slash", args{`/`}, `/`},
|
||||||
|
{"single-backslash", args{`\`}, `\`},
|
||||||
|
{"multiple-slashes", args{`///`}, `/`},
|
||||||
|
{"multiple-backslashes", args{`\\\`}, `\`},
|
||||||
|
{"multiple-mixed-slash-first", args{`/\\`}, `/`},
|
||||||
|
{"multiple-mixed-backslash-first", args{`\//`}, `\`},
|
||||||
|
{"nothing-trailing", args{`nothing/trailing\here`}, `nothing/trailing\here`},
|
||||||
|
{"trailing-space", args{`trailing/space/ `}, `trailing/space/ `},
|
||||||
|
{"trailing-slash", args{`trailing/slash/`}, `trailing/slash`},
|
||||||
|
{"trailing-slashes", args{`trailing/slashes///`}, `trailing/slashes`},
|
||||||
|
{"trailing-backslash", args{`trailing\backslash\`}, `trailing\backslash`},
|
||||||
|
{"trailing-backslashes", args{`trailing\backslashes\\\`}, `trailing\backslashes`},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := TrimTrailingSep(tt.args.path); got != tt.want {
|
||||||
|
t.Errorf("TrimTrailingSep() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user