Skip to content

Commit e4a0711

Browse files
committed
filename: validate input
1 parent 52a5a70 commit e4a0711

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

+stdlib/filename.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@
77

88
function f = filename(p, method)
99
arguments
10-
p
11-
method = 'pattern'
10+
p string
11+
method {mustBeMember(method, {'pattern', 'regexp'})} = 'pattern'
1212
end
1313

1414
% the pattern method is a few percent faster than regexp
1515
switch method
16-
case 'pattern', f = extractAfter(p, asManyOfPattern(wildcardPattern + ("/" | filesep)));
16+
case 'pattern'
17+
f = extractAfter(p, asManyOfPattern(wildcardPattern + ("/" | filesep)));
1718
case 'regexp'
1819
f = regexp(p, ['[^/\' filesep ']*$'], 'match', 'once');
19-
try %#ok<TRYNC>
20-
f(ismissing(f)) = "";
21-
end
22-
otherwise, error('unknown method %s', method)
20+
f(ismissing(f)) = "";
2321
end
2422

2523
end

+stdlib/private/choose_method.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
end
2727
end
2828

29-
error("Could not find %s using %s", name, join(method, ','))
29+
error("Could not find any %s capable of running, using %s", name, join(method, ','))
3030

3131
end

test/TestFilename.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ function test_filename_empty(tc, e, method)
3131

3232
function p = init_p()
3333
p = {
34-
{'', ''}, ...
34+
{'', ""}, ...
3535
{"", ""}, ...
3636
{"Hi", "Hi"}, ...
3737
{"/a/b/c", "c"}, ...
38-
{'a/b/c.txt', 'c.txt'}, ...
38+
{'a/b/c.txt', "c.txt"}, ...
3939
{"a///b//c.txt.gz", "c.txt.gz"}, ...
4040
{"a/b/.hello", ".hello"}
4141
};

0 commit comments

Comments
 (0)