Skip to content

Commit 0516e5a

Browse files
committed
parent: handle Windows root paths
1 parent 590f666 commit 0516e5a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

+stdlib/parent.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
else
1313
% drop duplicated slashes in the parent path
1414
p = regexprep(p, "//+", "/");
15+
16+
if ispc && any(strlength(p) == [2,3]) && isletter(extractBetween(p, 1, 1) && extractBetween(p, 2, 2) == ":")
17+
% 2 or 3 char drive letter
18+
p = stdlib.root(p);
19+
return
20+
end
1521
% have to drop_slash on input to get expected parent path
1622
p = strip(stdlib.posix(p), "right", "/");
1723
j = strfind(p, "/");

test/TestFilePure.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
sub_is_subdir
1818
ref_is_subdir
1919

20-
in_parent = {"", ".", "..", "../..", "a/", "a/b", "a/b/", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt", "a/////b////c"}
21-
ref_parent = {".", ".", ".", "..", ".", "a", "a", "ab", "ab", "a/b/..", "a/b"}
20+
in_parent
21+
ref_parent
2222

2323
in_suffix = {"", "/foo/bar/baz", "/foo/bar/baz/", "foo/bar/baz.txt", "foo/bar/baz.txt.gz", ".stat", ".stat.txt"}
2424
ref_suffix = {"", "", "", ".txt", ".gz", ".stat", ".txt"}
@@ -37,11 +37,14 @@
3737
end
3838

3939
methods (TestParameterDefinition, Static)
40-
function [base_relative_to, other_relative_to, ref_relative_to, ref_proximate_to, in_root, ref_root] = init_relative_to(classToTest) %#ok<INUSD>
40+
function [base_relative_to, other_relative_to, ref_relative_to, ref_proximate_to, in_root, ref_root, in_parent, ref_parent] = init_relative_to(classToTest) %#ok<INUSD>
4141

4242
in_root = {"", "a/b", "./a/b", "../a/b", "/etc", "c:/etc"};
4343
ref_root = {"", "", "", "", "/", ""};
4444

45+
in_parent = {"", ".", "..", "../..", "a/", "a/b", "a/b/", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt", "a/////b////c", "c:/", "c:\", "c:/a/b", "c:\a/b"};
46+
ref_parent = {".", ".", ".", "..", ".", "a", "a", "ab", "ab", "a/b/..", "a/b", ".", ".", "c:/a", "c:\a"};
47+
4548
if ispc
4649

4750
base_relative_to = {'', 'Hello', 'Hello', ...
@@ -55,6 +58,11 @@
5558
ref_proximate_to = ref_relative_to;
5659
ref_proximate_to{end} = other_relative_to{end};
5760

61+
ref_root{12} = "c:/";
62+
ref_root{13} = "c:/";
63+
ref_root{14} = "c:/a";
64+
ref_root{15} = "c:/a";
65+
5866
ref_root{5} = "";
5967
ref_root{6} = "c:/";
6068

0 commit comments

Comments
 (0)