# HG changeset patch # User Rik # Date 1404073404 25200 # Node ID ca0d9844dfd78fd26b82bf5bdda3fa999286c28e # Parent afab3a2f57e7a14f225baf3eadcd24d6ee963dd5 Fix input validation for exist() which did not error on non-string input. * variables.cc (Fexist): Error out if NAME or TYPE fields are not strings. Add warning if input TYPE is unimplemented "class" field. Add warning to docstring about "class" field being unimplemented. diff -r afab3a2f57e7 -r ca0d9844dfd7 libinterp/corefcn/variables.cc --- a/libinterp/corefcn/variables.cc Sun Jun 29 12:58:22 2014 -0700 +++ b/libinterp/corefcn/variables.cc Sun Jun 29 13:23:24 2014 -0700 @@ -565,7 +565,7 @@ Check only for files and directories.\n\ \n\ @item @qcode{\"class\"}\n\ -Check only for classes.\n\ +Check only for classes. (Note: This option is accepted, but not currently implemented)\n\ @end table\n\ \n\ If no type is given, and there are multiple possible matches for name,\n\ @@ -586,16 +586,21 @@ if (nargin == 1 || nargin == 2) { - std::string name = args(0).string_value (); - - if (! error_state) + if (args(0).is_string ()) { + std::string name = args(0).string_value (); + if (nargin == 2) { - std::string type = args(1).string_value (); - - if (! error_state) - retval = symbol_exist (name, type); + if (args(1).is_string ()) + { + std::string type = args(1).string_value (); + + if (type == "class") + warning ("exist: \"class\" type argument is not implemented"); + + retval = symbol_exist (name, type); + } else error ("exist: TYPE must be a string"); } @@ -652,6 +657,12 @@ %!assert (exist (dirtmp, "dir"), 7) %!assert (exist (dirtmp, "file"), 7) +%!error exist () +%!error exist (1,2,3) +%!warning <"class" type argument is not implemented> exist ("a", "class"); +%!error exist ("a", 1) +%!error exist (1) + */ octave_value