Mercurial > octave
changeset 20241:8b1884214798
fullfile.m: allow UNC (\srv\share) paths on Windows systems (bug #44682).
* fullfile.m: Use strncmp to detect '\\' at start of path and preserve UNC
portion. Recode BIST test to check for elimination of multilple file
separators to apply to non-Windows systems only.
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Mon, 25 May 2015 20:04:45 +0200 |
parents | 35fc5ea83030 |
children | 78293a28f2a5 |
files | scripts/miscellaneous/fullfile.m |
diffstat | 1 files changed, 12 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/miscellaneous/fullfile.m Sun May 31 13:45:16 2015 +0100 +++ b/scripts/miscellaneous/fullfile.m Mon May 25 20:04:45 2015 +0200 @@ -42,6 +42,8 @@ ## replaced by backslashes; in addition drive letters are stripped of leading ## file separators to obtain a valid file path. ## +## Note: @code{fullfile} does not perform any validation of the resulting full +## filename. ## @seealso{fileparts, filesep} ## @end deftypefn @@ -54,12 +56,14 @@ "UniformOutput", false); else non_empty = cellfun ("isempty", varargin); + unc = 0; if (ispc && ! isempty (varargin)) - varargin = strrep (varargin, "/", filesep); + varargin = strrep (varargin, '/', filesep); + unc = strncmp (varargin{1}, '\\', 2); varargin(1) = regexprep (varargin{1}, '[\\/]*([a-zA-Z]:[\\/]*)', "$1"); endif filename = strjoin (varargin(! non_empty), filesep); - filename(strfind (filename, [filesep filesep])) = ""; + filename(unc + strfind (filename(1+unc : end), [filesep filesep])) = ""; endif endfunction @@ -87,7 +91,6 @@ %!assert (fullfile ("x", "", "y", ""), xfsy) %!assert (fullfile ("", "x", "", "y", ""), xfsy) %!assert (fullfile (fs), fs) -%!assert (fullfile (fs, fs), fs) %!assert (fullfile (fs, "x"), fsx) %!assert (fullfile (fs, xfs), fsxfs) %!assert (fullfile (fsx, fs), fsxfs) @@ -109,6 +112,12 @@ %! ['A:\' xfsyfs]); %! endif +## *nix specific - double backslash +%!test +%! if (isunix || ismac) +%! assert (fullfile (fs, fs), fs) +%! endif + ## Windows specific - drive letters and file sep type, cell array %!test %! if (ispc)