Skip to content

Commit b1bb485

Browse files
committed
note ambiguity in .. components is_subdir, proximate_to, relative_to
avoid testing these functions with .. components
1 parent 2963737 commit b1bb485

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

+stdlib/proximate_to.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
end
88

99
r = stdlib.relative_to(base, other);
10-
if stdlib.len(r) > 0
11-
return;
12-
end
1310

14-
r = other;
11+
if ~stdlib.len(r)
12+
r = other;
13+
end
1514

1615
end
1716

+stdlib/relative_to.m

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
end
88

99
% must remove trailing slashes
10-
base = stdlib.drop_slash(base);
11-
other = stdlib.drop_slash(other);
10+
b1 = stdlib.drop_slash(base);
11+
o1 = stdlib.drop_slash(other);
1212

13-
if strcmp(base, other)
13+
if strcmp(b1, o1)
1414
r = ".";
1515
return
1616
end
1717

1818
if stdlib.isoctave()
19-
b = javaObject("java.io.File", base).toPath();
20-
o = javaObject("java.io.File", other).toPath();
19+
b = javaObject("java.io.File", b1).toPath();
20+
o = javaObject("java.io.File", o1).toPath();
2121
else
22-
b = java.io.File(base).toPath();
23-
o = java.io.File(other).toPath();
22+
b = java.io.File(b1).toPath();
23+
o = java.io.File(o1).toPath();
2424
end
2525

2626
try
@@ -43,5 +43,4 @@
4343
%!assert(relative_to("/a/b", "/a/b"), ".")
4444
%!assert(relative_to("/a/b", "/a/b/c"), "c")
4545
%!assert(relative_to("/a/b", "/a/b/c/"), "c")
46-
%!assert(relative_to("a/b/..", "a/b"), "..")
4746
%!assert(relative_to("/a/b", "d"), "")

+stdlib/with_suffix.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@
1616
s = stdlib.stem(p);
1717

1818
if stdlib.len(s) == 0
19-
f = stdlib.join(p, suffix);
19+
f = stdlib.join(p, suffix, false);
2020
return
2121
end
2222

2323
if r == '.'
2424
f = s;
25-
elseif stdlib.isoctave()
25+
elseif ischar(r)
2626
f = strcat(r, '/', s);
2727
else
2828
f = r + "/" + s;
2929
end
3030

31-
f = f + suffix;
32-
31+
if ischar(r)
32+
f = strcat(f, suffix);
33+
else
34+
f = f + suffix;
3335
end
3436

37+
end
3538

36-
%!assert(with_suffix("", ""), "")
37-
%!assert(with_suffix("a.h5", ".nc"), "a.nc")
38-
%!assert(with_suffix("a", ".nc"), "a.nc")
39-
%!assert(with_suffix("a.h5", ""), "a")
40-
%!assert(with_suffix("a", ""), "a")
39+
%!assert(with_suffix("ab.h5", ".nc"), "ab.nc")
40+
%!assert(with_suffix("ab", ".nc"), "ab.nc")
41+
%!assert(with_suffix("ab.h5", ""), "ab")
42+
%!assert(with_suffix("ab", ""), "ab")

test/TestFilePure.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
{"Hello", "Hello/", "."}, ...
8383
{"./this/one", "./this/two", "../two"}, ...
8484
{"/path/same", "/path/same/hi/..", "hi/.."}, ...
85-
{"a/b/..", "a/b", ".."}, ...
8685
{"", "/", ""}, ...
8786
{"/", "", ""}, ...
8887
{"/", "/", "."}, ...
@@ -92,7 +91,8 @@
9291
{"/a/b", "/a/b", "."}, ...
9392
{"/a/b", "/a", ".."}, ...
9493
{"/a/b/c/d", "/a/b", "../.."}, ...
95-
{"/this/one", "/this/two", "../two"}};
94+
{"this/one", "this/two", "../two"}};
95+
% NOTE: ".." in relative_to is ambiguous including for python.pathlib, C++ <filesystem>, etc.
9696

9797
p_proximate_to = p_relative_to;
9898

@@ -111,6 +111,7 @@
111111
{"c:/path", "d:/path", ""}}];
112112

113113
p_proximate_to = p_relative_to;
114+
% NOTE: ".." in proximate_to is ambiguous including for python.pathlib, C++ <filesystem>, etc
114115

115116
p_proximate_to{6}{3} = "/";
116117
p_proximate_to{10}{3} = "c";
@@ -153,9 +154,9 @@
153154
{"a/b", "a/b", false}, ...
154155
{"a/b", "a/b/", false}, ...
155156
{"a/b", "a", true}, ...
156-
{"a/.c", "a", true}, ...
157-
{"a/b", "a/b/..", false} % tricky one
157+
{"a/.c", "a", true}
158158
};
159+
% NOTE: ".." in is_subidr is ambiguous
159160

160161
if ispc
161162
p_is_subdir{end+1} = {"c:\", "c:/", false};
@@ -272,7 +273,7 @@ function test_relative_to(tc, p_relative_to)
272273

273274
function test_proximate_to(tc, p_proximate_to)
274275
tc.assumeTrue(stdlib.has_java)
275-
tc.verifyEqual(stdlib.proximate_to(p_proximate_to{1}, p_proximate_to{2}), p_proximate_to{3})
276+
tc.verifyEqual(stdlib.proximate_to(p_proximate_to{1}, p_proximate_to{2}), p_proximate_to{3}, "proximate_to(" + p_proximate_to{1} + "," + p_proximate_to{2}+")")
276277
end
277278

278279

0 commit comments

Comments
 (0)