Sync path_conv.pp with msys2-runtime

This commit is contained in:
Christoph Reiter committed 2023-12-22 16:02:07 +01:00
1 parent 9cb0daa929
commit 3a20d2f1f5
1 file changed
+76 -2
+76 -2
View File
@@ -269,7 +269,7 @@ void find_end_of_rooted_path(const char** from, const char** to, int* in_string)
void sub_convert(const char** from, const char** to, char** dst, const char* dstend, int* in_string) {
const char* copy_from = *from;
path_type type = find_path_start_and_type(from, false, *to);
debug_printf("found type %d for path %s\n", type, copy_from);
debug_printf("found type %d for path %s", type, copy_from);
if (type == POSIX_PATH_LIST) {
find_end_of_posix_list(to, in_string);
@@ -372,6 +372,65 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
if (*it == '\0' || it == end) return NONE;
/*
* Skip path mangling when environment indicates it.
*/
const char *no_pathconv = getenv ("MSYS_NO_PATHCONV");
if (no_pathconv) {
*src = end;
return NONE;
}
/* Let's not convert ~/.file to ~C:\msys64\.file */
if (*it == '~') {
skip_p2w:
*src = end;
return NONE;
}
/*
* Prevent Git's :file.txt and :/message syntax from beeing modified.
*/
if (*it == ':')
goto skip_p2w;
while (it != end && *it) {
switch (*it) {
case '`':
case '\'':
case '"':
case '*':
case '?':
case '[':
case ']':
goto skip_p2w;
case '/':
if (it + 1 < end && it[1] == '~')
goto skip_p2w;
break;
case ':':
// Avoid mangling IPv6 addresses
if (it + 1 < end && it[1] == ':')
goto skip_p2w;
// Leave Git's <rev>:./name syntax alone
if (it + 1 < end && it[1] == '.') {
if (it + 2 < end && it[2] == '/')
goto skip_p2w;
if (it + 3 < end && it[2] == '.' && it[3] == '/')
goto skip_p2w;
}
break;
case '@':
// Paths do not contain '@@'
if (it + 1 < end && it[1] == '@')
goto skip_p2w;
}
++it;
}
it = *src;
while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
recurse = true;
it = ++*src;
@@ -380,6 +439,13 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
path_type result = NONE;
if (it + 1 == end) {
switch (*it) {
case '/': return ROOTED_PATH ;
default: return SIMPLE_WINDOWS_PATH;
}
}
if (isalpha(*it) && *(it + 1) == ':') {
if (*(it + 2) == '\\') {
return SIMPLE_WINDOWS_PATH;
@@ -437,6 +503,8 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
int starts_with_minus = 0;
int starts_with_minus_alpha = 0;
int only_dots = *it == '.';
int has_slashes = 0;
if (*it == '-') {
starts_with_minus = 1;
it += 1;
@@ -455,7 +523,7 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
if (isalpha(ch) && (*(it2+1) == ':') && (*(it2+2) == '/')) {
return SIMPLE_WINDOWS_PATH;
}
if (ch == '/'&& memchr(it2, ',', end - it) == NULL) {
if (ch == '/'&& memchr(it2, ',', end - it2) == NULL) {
*src = it2;
return find_path_start_and_type(src, true, end);
}
@@ -480,11 +548,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
if (ch == '/' && *(it2 + 1) == '/') {
return URL;
} else {
if (!only_dots && !has_slashes)
goto skip_p2w;
return POSIX_PATH_LIST;
}
} else if (memchr(it2, '=', end - it) == NULL) {
return SIMPLE_WINDOWS_PATH;
}
} else if (ch != '.') {
only_dots = 0;
if (ch == '/' || ch == '\\')
has_slashes = 1;
}
}