Skip to content

Commit f4bdb71

Browse files
committed
expanduser: ignore inputs like ~abc
1 parent a2a1f68 commit f4bdb71

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

+stdlib/+fileio/expanduser.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
function expanded = expanduser(p)
1+
function e = expanduser(p)
22

33
arguments
44
p string {mustBeScalarOrEmpty}
55
end
66

7-
expanded = p;
7+
e = p;
88

9-
if ~startsWith(expanded, "~")
9+
if ~all(startsWith(e, "~")) || (all(strlength(e) > 1) && ~all(startsWith(e, "~/")))
1010
return
1111
end
1212

1313
home = stdlib.fileio.homedir();
1414

1515
if ~isempty(home)
16-
expanded = fullfile(home, extractAfter(expanded, 1));
16+
e = fullfile(home, extractAfter(e, 1));
1717
end
1818

1919
end %function

+stdlib/+fileio/homedir.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
return
88
end
99

10-
home = string(java.lang.System.getProperty("user.home"));
10+
home = stdlib.fileio.posix(java.lang.System.getProperty("user.home"));
1111

1212
h = home;
1313

+stdlib/+test/TestFileImpure.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function test_expanduser(tc)
99
tc.verifyEmpty(expanduser(string.empty))
1010
tc.verifyEqual(expanduser(""), "")
1111

12+
tc.verifyEqual(expanduser("~abc"), "~abc")
13+
1214
tc.verifyFalse(startsWith(expanduser('~/foo'), "~"))
1315

1416
tc.verifyTrue(endsWith(expanduser('~/foo'), "foo"))

0 commit comments

Comments
 (0)