changeset 18240:3d22b24863b9

ls.m: Enclose paths with spaces in double quotes on Windows (bug #40989). * ls.m: Only enclose paths in double quotes on Windows systems. Remove now redundant check for '/' at end of filename. For UNIX systems, pass special characters '[]' through to shell.
author Rik <rik@octave.org>
date Tue, 07 Jan 2014 15:15:47 -0800
parents c0f036b5e292
children 9feb46ac6847
files scripts/miscellaneous/ls.m
diffstat 1 files changed, 8 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/ls.m	Thu Jan 02 10:12:36 2014 -0500
+++ b/scripts/miscellaneous/ls.m	Tue Jan 07 15:15:47 2014 -0800
@@ -60,24 +60,15 @@
 
   if (nargin > 0)
     args = tilde_expand (varargin);
-    is_dos = (ispc () && ! isunix ());
-    if (is_dos)
-      optsep = "/";
+    if (ispc () && ! isunix ())
+      idx = ! strncmp (args, '/', 1);
+      ## Enclose paths, potentially having spaces, in double quotes:
+      args(idx) = strcat ('"', args(idx), '"');    
+      ## shell (cmd.exe) on MinGW uses '^' as escape character
+      args = regexprep (args, '([^\w.*?])', '^$1');
     else
-      optsep = "-";
-    endif
-    idx = ! strncmp (args, optsep, 1);
-    ## Enclose paths, potentially having spaces, in double quotes:
-    args(idx) = strcat ('"', args(idx), '"');    
-    if (is_dos)
-      ## shell (cmd.exe) on MinGW uses '^' as escape character
-      args = regexprep (args, '([^\w.*? -])', '^$1');
-      ## Strip UNIX directory character which looks like an option to dir cmd.
-      if (args{end}(end) == '/')
-        args{end}(end) = "";
-      endif
-    else
-      args = regexprep (args, '([^\w.*? -])', '\\$1');
+      ## Escape any special characters in filename
+      args = regexprep (args, '([^\w.*?-[]])', '\\$1');
     endif
     args = sprintf ("%s ", args{:});
   else