Ensure path relativeTo() is nothrow.
This commit is contained in:
parent
b61b646236
commit
cc66180ad8
|
@ -67,7 +67,7 @@ Path relativeTo(Path)(Path path, Path base_path) @safe
|
||||||
enum up = Path.Segment2("..", Path.defaultSeparator);
|
enum up = Path.Segment2("..", Path.defaultSeparator);
|
||||||
auto ret = Path(base_nodes.map!(p => up).chain(nodes));
|
auto ret = Path(base_nodes.map!(p => up).chain(nodes));
|
||||||
if (path.endsWithSlash) {
|
if (path.endsWithSlash) {
|
||||||
if (ret.empty) return Path("." ~ path.toString()[$-1]);
|
if (ret.empty) return Path.fromTrustedString("." ~ path.toString()[$-1]);
|
||||||
else ret.endsWithSlash = true;
|
else ret.endsWithSlash = true;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -142,6 +142,12 @@ unittest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nothrow unittest {
|
||||||
|
auto p1 = PosixPath.fromTrustedString("/foo/bar/baz");
|
||||||
|
auto p2 = PosixPath.fromTrustedString("/foo/baz/bam");
|
||||||
|
assert(p2.relativeTo(p1).toString == "../../baz/bam");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Computes the relative path to this path from `base_path` using web path rules.
|
/** Computes the relative path to this path from `base_path` using web path rules.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue