Skip to content

Commit

Permalink
parent: handle duplicated slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Oct 7, 2024
1 parent 861082f commit 590f666
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions +stdlib/parent.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
% java is about 10x slower than intrinsic
p = java.io.File(p).getParent();
else
% drop duplicated slashes in the parent path
p = regexprep(p, "//+", "/");
% have to drop_slash on input to get expected parent path
p = strip(stdlib.posix(p), "right", "/");
j = strfind(p, "/");
Expand Down
4 changes: 2 additions & 2 deletions test/TestFilePure.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
sub_is_subdir
ref_is_subdir

in_parent = {"", ".", "..", "../..", "a/b", "a/b/", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt"}
ref_parent = {".", ".", ".", "..", "a", "a", "ab", "ab", "a/b/.."}
in_parent = {"", ".", "..", "../..", "a/", "a/b", "a/b/", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt", "a/////b////c"}
ref_parent = {".", ".", ".", "..", ".", "a", "a", "ab", "ab", "a/b/..", "a/b"}

in_suffix = {"", "/foo/bar/baz", "/foo/bar/baz/", "foo/bar/baz.txt", "foo/bar/baz.txt.gz", ".stat", ".stat.txt"}
ref_suffix = {"", "", "", ".txt", ".gz", ".stat", ".txt"}
Expand Down

0 comments on commit 590f666

Please sign in to comment.