Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pathconv issues related to relative paths in path lists #67

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions runtime/path_convert/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct test_data_t {
#error "Need to define both MSYSROOT and MSYSROOT2, or neither"
#endif
#else
#ifdef MSYSROOT
#ifdef MSYSROOT2
#error "Need to define both MSYSROOT and MSYSROOT2, or neither"
#endif
#if defined(__MSYS__) && defined(__LP64__)
Expand Down Expand Up @@ -177,10 +177,11 @@ static const test_data datas[] = {
,{"@/foo/bar@", "@" MSYSROOT2 "/foo/bar@", false}
,{"'@/foo/bar'", "'@/foo/bar'", false}
,{"///foo/bar", "//foo/bar", false}
,{".:./", ".:./", false}
,{"..:./", "..:./", false}
,{"../:./", "../:./", false}
,{"../aa/:./", "../aa/:./", false}
,{".:./", ".;.\\", false}
,{"..:./", "..;.\\", false}
,{"../:./", "..\\;.\\", false}
,{"../:./", "..\\;.\\", false}
,{"../aa/:./", "..\\aa\\;.\\", false}
,{"../", "../", false}
,{"/foo/bar/", "" MSYSROOT2 "/foo/bar/", false}
,{"-MExtUtils::ParseXS=process_file", "-MExtUtils::ParseXS=process_file", false}
Expand Down Expand Up @@ -236,6 +237,12 @@ static const test_data datas[] = {
{".:/tmp/", ".;" MSYSROOT "\\tmp\\", false},
{"..:/tmp/", "..;" MSYSROOT "\\tmp\\", false},
{".:..:/tmp/", ".;..;" MSYSROOT "\\tmp\\", false},
{"/this:./there", MSYSROOT "\\this;.\\there", false},
{"..:.:./this:/there", "..;.;.\\this;" MSYSROOT "\\there", false},
{"--dir=/this:./there", "--dir=" MSYSROOT "\\this;.\\there", false},
{"--dir=./this:./there", "--dir=.\\this;.\\there", false},
{"WEBINPUTS=.:../../../texk/web2c", "WEBINPUTS=.;..\\..\\..\\texk\\web2c", false},
{".:../../../texk/web2c", ".;..\\..\\..\\texk\\web2c", false},
{"/:/tmp/", MSYSROOT "\\;" MSYSROOT "\\tmp\\", false},
{0, 0, false}
};
Expand Down Expand Up @@ -280,6 +287,7 @@ int main() {
int passed = 0;
int total = 0;
for ( const test_data *it = &datas[0]; it && it->src; ++it ) {
printf("---\n");
total += 1;
const char *path = it->src;
const size_t blen = strlen(it->dst)*2 + 10;
Expand Down
38 changes: 36 additions & 2 deletions runtime/path_convert/src/path_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", type, copy_from);
debug_printf("found type %d for path %s\n", type, copy_from);

if (type == POSIX_PATH_LIST) {
find_end_of_posix_list(to, in_string);
Expand Down Expand Up @@ -389,6 +389,40 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
return NONE;
}

/*
* Discern between Git's `<rev>:<path>`, SCP's `<host>:<path>` pattern
* (which is not a path list but may naively look like one) on the one
* hand, and path lists starting with `/<path>`, `./<path>` or `../<path>`
* on the other hand.
*/
bool potential_path_list = *it == '/' ||
(*it == '.' &&
(it + 1 == end || it[1] == '\0' || it[1] == ':' || it[1] == '/' ||
(it[1] == '.' &&
(it + 2 == end || it[2] == '\0' || it[2] == ':' || it[2] == '/'))));

/*
* Determine if assignment to an environment variable takes place (and
* skip Git/SCP handling if so)
*/
bool potential_command_scope_env = false;
if (isalpha(*it) || *it == '_' || *it == '-') {
++it;

if (it != end) {
if (*it == '-')
++it;

while (it != end && *it && (isalnum(*it) || *it == '_')) {
++it;
}

if (*it == '=')
potential_command_scope_env = true;
}
it = *src;
}

/*
* Prevent Git's :file.txt and :/message syntax from beeing modified.
*/
Expand All @@ -414,7 +448,7 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
goto skip_p2w;

// Leave Git's <rev>:./name syntax alone
if (it + 1 < end && it[1] == '.') {
if (!potential_path_list && !potential_command_scope_env && it + 1 < end && it[1] == '.') {
if (it + 2 < end && it[2] == '/')
goto skip_p2w;
if (it + 3 < end && it[2] == '.' && it[3] == '/')
Expand Down