# HG changeset patch # User Philip Nienhuis # Date 1432577085 -7200 # Node ID 8b18842147981d1812de52fb86d963a975c7e0bc # Parent 35fc5ea830305c154d90e9416d09e15fdec489e5 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. diff --git a/scripts/miscellaneous/fullfile.m b/scripts/miscellaneous/fullfile.m --- a/scripts/miscellaneous/fullfile.m +++ b/scripts/miscellaneous/fullfile.m @@ -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)