Skip to content

Commit 4833b7e

Browse files
committed
Merge branch 'js/normalize-path-copy-ceil'
A pathname that begins with "//" or "\\" on Windows is special but path normalization logic was unaware of it. * js/normalize-path-copy-ceil: normalize_path_copy(): fix pushing to //server/share/dir on Windows
2 parents 0cfdda3 + 7814fbe commit 4833b7e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

path.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ const char *remove_leading_path(const char *in, const char *prefix)
991991
*
992992
* Performs the following normalizations on src, storing the result in dst:
993993
* - Ensures that components are separated by '/' (Windows only)
994-
* - Squashes sequences of '/'.
994+
* - Squashes sequences of '/' except "//server/share" on Windows
995995
* - Removes "." components.
996996
* - Removes ".." components, and the components the precede them.
997997
* Returns failure (non-zero) if a ".." component appears as first path
@@ -1014,17 +1014,22 @@ const char *remove_leading_path(const char *in, const char *prefix)
10141014
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
10151015
{
10161016
char *dst0;
1017-
int i;
1017+
const char *end;
10181018

1019-
for (i = has_dos_drive_prefix(src); i > 0; i--)
1020-
*dst++ = *src++;
1019+
/*
1020+
* Copy initial part of absolute path: "/", "C:/", "//server/share/".
1021+
*/
1022+
end = src + offset_1st_component(src);
1023+
while (src < end) {
1024+
char c = *src++;
1025+
if (is_dir_sep(c))
1026+
c = '/';
1027+
*dst++ = c;
1028+
}
10211029
dst0 = dst;
10221030

1023-
if (is_dir_sep(*src)) {
1024-
*dst++ = '/';
1025-
while (is_dir_sep(*src))
1026-
src++;
1027-
}
1031+
while (is_dir_sep(*src))
1032+
src++;
10281033

10291034
for (;;) {
10301035
char c = *src;

0 commit comments

Comments
 (0)