Mercurial > octave
changeset 28187:3faa700d64d4 stable
inputParser.m: Fix error with cell array Optional argument (bug #58112)
* inputParser.m (is_argname): Validate input parameter "name" is a string
before continuing. Add BIST test for bug #58112.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 05 Apr 2020 14:55:49 -0700 |
parents | c26838a3afa6 |
children | ad33d23d264f 5624fd0c5efb |
files | scripts/miscellaneous/inputParser.m |
diffstat | 1 files changed, 23 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/miscellaneous/inputParser.m Mon Mar 30 11:41:28 2020 -0700 +++ b/scripts/miscellaneous/inputParser.m Sun Apr 05 14:55:49 2020 -0700 @@ -531,15 +531,20 @@ endfunction function r = is_argname (this, type, name) - if (this.CaseSensitive) - r = isfield (this.(type), name); - this.last_name = name; - else - fnames = this.([type "Names"]); - l = strcmpi (name, fnames); - r = any (l(:)); - if (r) - this.last_name = fnames{l}; + r = ischar (name) && isrow (name); + if (r) + if (this.CaseSensitive) + r = isfield (this.(type), name); + if (r) + this.last_name = name; + endif + else + fnames = this.([type "Names"]); + l = strcmpi (name, fnames); + r = any (l(:)); + if (r) + this.last_name = fnames{l}; + endif endif endif endfunction @@ -830,3 +835,12 @@ %! p = inputParser; %! p.addParameter ("a", [], @ischar); %! p.parse ("a", 1); + +%!test <*58112> +%! p = inputParser (); +%! p.addRequired ("first"); +%! p.addOptional ("second", []); +%! p.parse (1, {"test", 1, 2, 3}); +%! r = p.Results; +%! assert (r.first, 1); +%! assert (r.second, {"test", 1, 2, 3});