Skip to content

Commit b7bdcc2

Browse files
agockeelinor-fung
andauthored
Fix UNC paths (#110033)
If the input file was a network path then the raw path returned by GetFinalPathByHandle may return a UNC extended path. If so, and if the original path wasn't a UNC extended path, and the original path doesn't need normalization, we want to use the original path. Co-authored-by: Elinor Fung <[email protected]>
1 parent 73a9330 commit b7bdcc2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/native/corehost/hostmisc/pal.windows.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,12 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging)
898898
}
899899
}
900900

901-
// Remove the \\?\ prefix, unless it is necessary or was already there
902-
if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) &&
901+
// Remove the UNC extended prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there
902+
if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && str.length() < MAX_PATH)
903+
{
904+
str.replace(0, LongFile::UNCExtendedPathPrefix.size(), LongFile::UNCPathPrefix);
905+
}
906+
else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) &&
903907
!LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size())))
904908
{
905909
str.erase(0, LongFile::ExtendedPrefix.size());

0 commit comments

Comments
 (0)