diff --git a/internal/manager/config/config.go b/internal/manager/config/config.go index 182d9fac..4a955b91 100644 --- a/internal/manager/config/config.go +++ b/internal/manager/config/config.go @@ -378,15 +378,7 @@ func (c *Conf) constructVariableLookupTableForVars(vars map[string]Variable) { // Given a variable 'apps' with value '/path/to/apps', // '/path/to/apps/blender' should be remapped to '{apps}/blender'. if variable.IsTwoWay { - if strings.Contains(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, "/") + value.Value = crosspath.TrimTrailingSep(value.Value) } if value.Platform != "" { diff --git a/pkg/crosspath/crosspath.go b/pkg/crosspath/crosspath.go index 31ce52b0..7203ef4a 100644 --- a/pkg/crosspath/crosspath.go +++ b/pkg/crosspath/crosspath.go @@ -149,3 +149,16 @@ func pathSepForPlatform(platform string) string { func isPathSep(r rune) bool { 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 +} diff --git a/pkg/crosspath/crosspath_test.go b/pkg/crosspath/crosspath_test.go index 01ed3ef4..7ca992a2 100644 --- a/pkg/crosspath/crosspath_test.go +++ b/pkg/crosspath/crosspath_test.go @@ -1,7 +1,5 @@ package crosspath -// SPDX-License-Identifier: GPL-3.0-or-later - import ( "path" "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) + } + }) + } +}