changeset 14007:caa7439203f2

ls.m: Fix handling of arguments with dashes (-l) (Bug #34950) * ls.m: pass cellstr to regexprep, rather than comma-separated list. Add %!test block.
author Rik <octave@nomad.inbox5.com>
date Wed, 07 Dec 2011 10:10:10 -0800
parents 54f76558c41a
children a73e110857e4
files scripts/miscellaneous/ls.m
diffstat 1 files changed, 32 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/ls.m	Wed Dec 07 06:55:12 2011 -0500
+++ b/scripts/miscellaneous/ls.m	Wed Dec 07 10:10:10 2011 -0800
@@ -46,49 +46,49 @@
     ls_command ();
   endif
 
-  if (iscellstr (varargin))
-
-    args = tilde_expand (varargin);
+  if (! iscellstr (varargin))
+    error ("ls: all arguments must be character strings");
+  endif
 
-    if (nargin > 0)
-      if (ispc () && ! isunix ())
-        ## shell (cmd.exe) on MinGW uses '^' as escape character
-        args = regexprep (args{:}, '([^\w.*?])', '^$1');
-      else
-        args = regexprep (args{:}, '([^\w.*?])', '\$1');
-      endif
+  if (nargin > 0)
+    args = tilde_expand (varargin);
+    if (ispc () && ! isunix ())
+      ## shell (cmd.exe) on MinGW uses '^' as escape character
+      args = regexprep (args, '([^\w.*? -])', '^$1');
     else
-      args = "";
+      args = regexprep (args, '([^\w.*? -])', '\$1');
     endif
-
-    cmd = sprintf ("%s %s", __ls_command__, args);
-
-    if (page_screen_output () || nargout > 0)
+    args = sprintf ("%s ", args{:});
+  else
+    args = "";
+  endif
 
-      [status, output] = system (cmd);
+  cmd = sprintf ("%s %s", __ls_command__, args);
+
+  if (page_screen_output () || nargout > 0)
+    [status, output] = system (cmd);
 
-      if (status == 0)
-        if (nargout == 0)
-          puts (output);
-        else
-          retval = strvcat (regexp (output, '\S+', 'match'){:});
-        endif
-      else
-        error ("ls: command exited abnormally with status %d\n", status);
-      endif
-
+    if (status != 0)
+      error ("ls: command exited abnormally with status %d\n", status);
+    elseif (nargout == 0)
+      puts (output);
     else
-      ## Just let the output flow if the pager is off.  That way the
-      ## output from things like "ls -R /" will show up immediately and
-      ## we won't have to buffer all the output.
-      system (cmd);
+      retval = strvcat (regexp (output, '\S+', 'match'){:});
     endif
-
   else
-    error ("ls: expecting all arguments to be character strings");
+    ## Just let the output flow if the pager is off.  That way the
+    ## output from things like "ls -R /" will show up immediately and
+    ## we won't have to buffer all the output.
+    system (cmd);
   endif
 
 endfunction
 
+
+%!test
+%! list = ls ();
+%! assert (ischar (list));
+%! assert (! isempty (list));
+
 %!error ls (1);