fix(path): use relative on empty root

relates to #2962
This commit is contained in:
Jan De Dobbeleer 2022-11-26 15:24:50 +01:00 committed by Jan De Dobbeleer
parent 3bc9e83814
commit 35edf3a93d
2 changed files with 7 additions and 0 deletions

View file

@ -99,6 +99,11 @@ func (pt *Path) setPaths() {
}
// ensure a clean path
pt.root, pt.relative = pt.replaceMappedLocations()
// this is a full replacement of the parent
if len(pt.root) == 0 {
pt.pwd = pt.relative
return
}
pathSeparator := pt.env.PathSeparator()
if !strings.HasSuffix(pt.root, pathSeparator) && len(pt.relative) > 0 {
pt.pwd = pt.root + pathSeparator + pt.relative

View file

@ -1350,6 +1350,7 @@ func TestReplaceMappedLocations(t *testing.T) {
Pwd string
Expected string
}{
{Pwd: "/c/l/k/f", Expected: "f"},
{Pwd: "/f/g/h", Expected: "/f/g/h"},
{Pwd: "/f/g/h/e", Expected: "^/e"},
{Pwd: "/a/b/c/d", Expected: "#"},
@ -1369,6 +1370,7 @@ func TestReplaceMappedLocations(t *testing.T) {
MappedLocations: map[string]string{
"/a/b/c/d": "#",
"/f/g/h/*": "^",
"/c/l/k/*": "",
},
},
}