Don't special case current directory relative paths.
This commit is contained in:
parent
a60d9f83df
commit
dd4cdb95c7
|
@ -162,7 +162,8 @@ def _relativize(path, start):
|
|||
will fail if `path` is not beneath `start` (rather than use parent segments to
|
||||
walk up to the common file system root).
|
||||
|
||||
Relativizing paths that start with parent directory references is not allowed.
|
||||
Relativizing paths that start with parent directory references only works if
|
||||
the path both start with the same initial parent references.
|
||||
|
||||
Args:
|
||||
path: The path to relativize.
|
||||
|
@ -176,9 +177,6 @@ def _relativize(path, start):
|
|||
start_segments = []
|
||||
start_length = len(start_segments)
|
||||
|
||||
if (path.startswith("..") or start.startswith("..")):
|
||||
fail("Cannot relativize paths above the current (unknown) directory")
|
||||
|
||||
if (path.startswith("/") != start.startswith("/") or
|
||||
len(segments) < start_length):
|
||||
fail("Path '%s' is not beneath '%s'" % (path, start))
|
||||
|
|
|
@ -195,6 +195,10 @@ def _relativize_test(ctx):
|
|||
# Try a case where a parent directory is normalized away.
|
||||
asserts.equals(env, "baz", paths.relativize("foo/bar/../baz", "foo"))
|
||||
|
||||
# Relative paths work, as long as they share a common start.
|
||||
asserts.equals(env, "file", paths.relativize("../foo/bar/baz/file", "../foo/bar/baz"))
|
||||
asserts.equals(env, "baz/file", paths.relativize("../foo/bar/baz/file", "../foo/bar"))
|
||||
|
||||
# TODO(allevato): Test failure cases, once that is possible.
|
||||
|
||||
unittest.end(env)
|
||||
|
|
Loading…
Reference in New Issue