# HG changeset patch # User Markus Mützel # Date 1649660966 -7200 # Mon Apr 11 09:09:26 2022 +0200 # Branch stable # Node ID fd0ff96322bff5e2aaea469dd31f210cf3d9d59d # Parent e219aacda1e55623dcbc0910e851dda41f98a396 Fix "ls" with glob patterns on Windows (bug #62282). * scripts/miscellaneous/ls.m: Exclude glob patterns from quoted part of string. diff -r e219aacda1e5 -r fd0ff96322bf scripts/miscellaneous/ls.m --- a/scripts/miscellaneous/ls.m Sun Apr 10 14:34:05 2022 -0700 +++ b/scripts/miscellaneous/ls.m Mon Apr 11 09:09:26 2022 +0200 @@ -66,20 +66,19 @@ if (nargin > 0) args = tilde_expand (varargin); + 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 - ## Escape any special characters in filename - args = regexprep (args, '([^][\w.*?-])', '\\$1'); - ## Undo escaped spaces following command args - ## Only used for command form where single str contains many args. - ## Example: list = ls ("-l /usr/bin") - args = regexprep (args, '(-\w+)(?:\\ )+', '$1 '); + ## Replace backslashes with forward slashes + args = strrep (args, '\', '/'); endif + + ## Escape any special characters in filename + args = regexprep (args, '([^][\w.*?-])', '\\$1'); + ## Undo escaped spaces following command args + ## Only used for command form where single str contains many args. + ## Example: list = ls ("-l /usr/bin") + args = regexprep (args, '(-\w+)(?:\\ )+', '$1 '); + args = sprintf ("%s ", args{:}); else args = "";