Fixing Path.relativeTo for directories, a Path whith endsWithSlash==true had this property stripped, when made relative to another Path.
1 parent 1e02854 commit 3e9c625f38796e98110e9ecc21b583995c028506
@Matthias Dondorff Matthias Dondorff authored on 1 Mar 2014
Showing 1 changed file
View
31
source/dub/internal/vibecompat/inet/path.d
Path ret = Path(null, false);
ret.m_endsWithSlash = true;
foreach( i; 0 .. nup ) ret ~= "..";
ret ~= Path(m_nodes[parentPath.length-nup .. $], false);
ret.m_endsWithSlash = this.m_endsWithSlash;
return ret;
}
/// The last entry of the path
assert(dotpathp.toString() == "/test/../test2/././x/y");
dotpathp.normalize();
assert(dotpathp.toString() == "/test2/x/y");
}
}
 
{
auto parentpath = "/path/to/parent";
auto parentpathp = Path(parentpath);
auto subpath = "/path/to/parent/sub/";
auto subpathp = Path(subpath);
auto subpath_rel = "sub/";
assert(subpathp.relativeTo(parentpathp).toString() == subpath_rel);
auto subfile = "/path/to/parent/child";
auto subfilep = Path(subfile);
auto subfile_rel = "child";
assert(subfilep.relativeTo(parentpathp).toString() == subfile_rel);
}
}