@@ -132,6 +132,8 @@ size_t git_win32__canonicalize_path(wchar_t *str, size_t len)
132132 static const wchar_t dosdevices_prefix [] = L"\\\?\?\\" ;
133133 static const wchar_t nt_prefix [] = L"\\\\?\\" ;
134134 static const wchar_t unc_prefix [] = L"UNC\\" ;
135+ static const wchar_t unc_canonicalized_prefix [] = L"\\\\" ;
136+
135137 size_t to_advance = 0 ;
136138
137139 /* "\??\" -- DOS Devices prefix */
@@ -150,8 +152,18 @@ size_t git_win32__canonicalize_path(wchar_t *str, size_t len)
150152 /* "\??\UNC\", "\\?\UNC\" -- UNC prefix */
151153 if (to_advance && len >= CONST_STRLEN (unc_prefix ) &&
152154 !wcsncmp (str + to_advance , unc_prefix , CONST_STRLEN (unc_prefix ))) {
153- to_advance += CONST_STRLEN (unc_prefix );
154- len -= CONST_STRLEN (unc_prefix );
155+ /**
156+ * The proper Win32 path for a UNC share has "\\" at beginning of it
157+ * and looks like "\\server\share\<folderStructure>".
158+ * So, remove th UNC prefix, but leave room for a "\\"
159+ */
160+ to_advance += (CONST_STRLEN (unc_prefix ) - CONST_STRLEN (unc_canonicalized_prefix ));
161+ len -= (CONST_STRLEN (unc_prefix ) - CONST_STRLEN (unc_canonicalized_prefix ));
162+
163+ /**
164+ * Place a "\\" in the string so the result is "\\server\\share\<folderStructure>"
165+ */
166+ memmove (str + to_advance , unc_canonicalized_prefix , CONST_STRLEN (unc_canonicalized_prefix ) * sizeof (wchar_t ));
155167 }
156168
157169 if (to_advance ) {
0 commit comments