Mercurial > octave
changeset 28740:fed3b09f2efc
Fix some issues in uicontrol input validation (bug #59113)
* __uiobject_split_args__.m: Use strcmpi() only on potential "PROPERTY" string
arguments rather than on all arguments to uicontrol().
* uicontrol.m: Switch strcmp() to strcmpi() so as to be case insensitive when
detecting warning conditon where "Style" is "frame". Only use strcmpi() on
string arguments rather than on all arguments. Fix incorrect test which was
using variable "varargin" rather than required variable "args". Add BIST
test to check that input validation is correct.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 14 Sep 2020 11:54:17 -0700 |
parents | 3eb2fab71028 |
children | 2cd4a32cbc4b |
files | scripts/gui/private/__uiobject_split_args__.m scripts/gui/uicontrol.m |
diffstat | 2 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/gui/private/__uiobject_split_args__.m Fri Sep 20 08:48:45 2019 +0200 +++ b/scripts/gui/private/__uiobject_split_args__.m Mon Sep 14 11:54:17 2020 -0700 @@ -46,13 +46,13 @@ endif if (! isempty (args)) - i = find (strcmpi (args, "parent"), 1, "first"); - if (! isempty (i) && numel (args) > i) - parent = args{i+1}; + i = find (strcmpi (args(1:2:end), "parent"), 1, "first"); + if (! isempty (i) && numel (args) >= 2*i) + parent = args{2*i}; if (! ishghandle (parent)) error ("%s: invalid parent handle.", who); endif - args(i:i+1) = []; + args((2*i-1):2*i) = []; endif endif
--- a/scripts/gui/uicontrol.m Fri Sep 20 08:48:45 2019 +0200 +++ b/scripts/gui/uicontrol.m Mon Sep 14 11:54:17 2020 -0700 @@ -121,9 +121,9 @@ {"figure", "uipanel", "uibuttongroup"}); ## Validate style - idx = find (strcmp (args, "style"), 1, "last"); - if (! isempty (idx)) - if (idx < numel (args) && strcmp (varargin{idx+1}, "frame")) + idx = find (strcmpi (args(1:2:end), "style"), 1, "last"); + if (! isempty (idx) && 2*idx <= numel (args)) + if (strcmpi (args{2*idx}, "frame")) warning ("Octave:unimplemented-matlab-functionality", 'uicontrol: "frame" style is not implemented. Use uipanel() or uibuttongroup() instead'); endif @@ -136,3 +136,12 @@ endif endfunction + + +%!warning <"frame" style is not implemented> +%! hf = figure ("visible", "off"); +%! unwind_protect +%! h = uicontrol (hf, "string", "Hello World", "Style", "frame"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect