Skip to content

Commit

Permalink
Fix UNC paths
Browse files Browse the repository at this point in the history
If the input file was a network path then the raw path returned by
GetFinalPathByHandle may return a UNC path. If so, and if the original
path wasn't a UNC path, we want to remove the UNC prefix unless it was
necessary to fully resolve the path.
  • Loading branch information
agocke committed Nov 21, 2024
1 parent 00ba6d5 commit dd27740
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/native/corehost/hostmisc/pal.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,13 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging)
}
}

// Remove the \\?\ prefix, unless it is necessary or was already there
if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) &&
// Remove the UNC prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there
if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) &&
!LongFile::ShouldNormalize(str.substr(LongFile::UNCExtendedPathPrefix.size())))
{
str.erase(0, LongFile::UNCExtendedPathPrefix.size());
}
else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) &&
!LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size())))
{
str.erase(0, LongFile::ExtendedPrefix.size());
Expand Down

0 comments on commit dd27740

Please sign in to comment.