Skip to content

Commit e76a621

Browse files
committed
canonical, resolve: don't coerce type
1 parent 1a5a00e commit e76a621

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

+stdlib/canonical.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@
4242
end
4343
end
4444

45+
c =stdlib.posix(c);
46+
4547
if ~strlength(c)
4648
c = stdlib.normalize(e);
4749
end
4850

49-
c = string(stdlib.posix(c));
51+
if isstring(p)
52+
c = string(c);
53+
end
5054

5155
end
5256

+stdlib/expanduser.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
p {mustBeTextScalar}
1313
end
1414

15-
e = stdlib.posix(char(p));
15+
e = char(p);
1616

1717
L = length(e);
18-
if L == 0 || e(1) ~= '~' || (L > 1 && ~strcmp(e(1:2), '~/'))
18+
if L == 0 || e(1) ~= '~' || (L > 1 && ~startsWith(e(1:2), {'~/', ['~', filesep()]}))
1919
% noop
2020
else
2121
home = stdlib.homedir();

test/TestCanonical.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
{"", ""}, ...
66
{"not-exist", "not-exist"}, ...
77
{"a/../b", "b"}, ...
8-
{'~', string(stdlib.homedir())}, ...
8+
{'~', stdlib.homedir()}, ...
99
{"~", string(stdlib.homedir())}, ...
10-
{'~/', string(stdlib.homedir())}, ...
10+
{'~/', stdlib.homedir()}, ...
1111
{"~/", string(stdlib.homedir())}, ...
1212
{"~/..", string(stdlib.parent(stdlib.homedir()))}, ...
1313
{mfilename("fullpath") + ".m/..", string(stdlib.parent(mfilename("fullpath")))}, ...

test/TestResolve.m

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ function test_resolve_relative(tc)
1313

1414
% all non-existing files
1515

16-
tc.verifyEqual(stdlib.resolve(""), string(stdlib.posix(pwd())))
17-
1816
pabs = stdlib.resolve('2foo', true);
1917
pabs2 = stdlib.resolve('4foo', true);
2018
tc.verifyThat(pabs, ~StartsWithSubstring("2"))
@@ -49,19 +47,17 @@ function test_resolve_fullpath(tc, p)
4947

5048
function p = init_resolve()
5149

52-
c = stdlib.posix(pwd());
53-
5450
p = {...
55-
{'', string(c)}, ...
56-
{"", string(c)}, ...
57-
{"not-exist", c + "/not-exist"}, ...
58-
{"a/../b", c + "/b"}, ...
59-
{'~', string(stdlib.homedir())}, ...
51+
{'', stdlib.posix(pwd())}, ...
52+
{"", string(stdlib.posix(pwd()))}, ...
53+
{'~', stdlib.homedir()}, ...
6054
{"~", string(stdlib.homedir())}, ...
61-
{'~/', string(stdlib.homedir())}, ...
55+
{'~/', stdlib.homedir()}, ...
6256
{"~/", string(stdlib.homedir())}, ...
6357
{"~/..", string(stdlib.parent(stdlib.homedir()))}, ...
6458
{mfilename("fullpath") + ".m/..", string(stdlib.parent(mfilename("fullpath")))}, ...
65-
{"~/not-exist/a/..", stdlib.homedir() + "/not-exist"}
59+
{"a/../b", stdlib.posix(pwd()) + "/b"}, ...
60+
{"not-exist", stdlib.posix(pwd()) + "/not-exist"}, ...
61+
{"~/not-exist/a/..", stdlib.homedir() + "/not-exist"}...
6662
};
6763
end

0 commit comments

Comments
 (0)