Skip to content

Commit 033aa36

Browse files
committed
with_suffix: handle corner case of leading dot filename
1 parent 1910244 commit 033aa36

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

+stdlib/with_suffix.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616
s = stdlib.stem(p);
1717

1818
if stdlib.len(s) == 0
19-
f = stdlib.join(p, suffix, false);
19+
if stdlib.len(stdlib.filename(p))
20+
if ischar(r)
21+
f = strcat(p, suffix);
22+
else
23+
f = p + suffix;
24+
end
25+
else
26+
f = stdlib.join(p, suffix, false);
27+
end
2028
return
2129
end
2230

@@ -40,3 +48,4 @@
4048
%!assert(with_suffix("ab", ".nc"), "ab.nc")
4149
%!assert(with_suffix("ab.h5", ""), "ab")
4250
%!assert(with_suffix("ab", ""), "ab")
51+
%!assert(with_suffix("ab/.h5", ".nc"), "ab/.nc")

test/TestFilePure.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
p_suffix = {{"", ""}, {"/a/b/c", ""}, {"/a/b/c/", ""}, {"a/b/c.txt", ".txt"}, {"a/b/c.txt.gz", ".gz"}, {".stat", ".stat"}, {".stat.txt", ".txt"}}
3333

34-
p_with_suffix = {{"foo.h5", ".nc", "foo.nc"}, {"c", "", "c"}, {"c.nc", "", "c"}, {"", ".nc", ".nc"}, {"a//b///c///", ".h5", "a/b/c/.h5"}}
34+
p_with_suffix = {{"foo.h5", ".nc", "foo.nc"}, {"c", "", "c"}, {"c.nc", "", "c"}, ...
35+
{"", ".nc", ".nc"}, {"a//b///c///", ".h5", "a/b/c/.h5"}, ...
36+
{"a/b/.h5", ".nc", "a/b/.h5.nc"}, {"a/b", ".nc", "a/b.nc"}};
3537

3638
p_norm = {
3739
{"", "."}, ...

0 commit comments

Comments
 (0)