Skip to content

Commit 590f666

Browse files
committed
parent: handle duplicated slashes
1 parent 861082f commit 590f666

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

+stdlib/parent.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
% java is about 10x slower than intrinsic
1111
p = java.io.File(p).getParent();
1212
else
13+
% drop duplicated slashes in the parent path
14+
p = regexprep(p, "//+", "/");
1315
% have to drop_slash on input to get expected parent path
1416
p = strip(stdlib.posix(p), "right", "/");
1517
j = strfind(p, "/");

test/TestFilePure.m

Lines changed: 2 additions & 2 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/b", "a/b/", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt"}
21-
ref_parent = {".", ".", ".", "..", "a", "a", "ab", "ab", "a/b/.."}
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"}
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"}

0 commit comments

Comments
 (0)