changeset 18914:ca0d9844dfd7

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.
author Rik <rik@octave.org>
date Sun, 29 Jun 2014 13:23:24 -0700
parents afab3a2f57e7
children 4cdab2973171
files libinterp/corefcn/variables.cc
diffstat 1 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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 <TYPE must be a string> exist ("a", 1)
+%!error <NAME must be a string> exist (1)
+
 */
 
 octave_value