commit
fec912ddac
@ -34,6 +34,9 @@ void do_getabsolute(char* result, const char* value, const char* relative_to)
|
|||||||
result[0] = '\0';
|
result[0] = '\0';
|
||||||
if (buffer[0] == '/') {
|
if (buffer[0] == '/') {
|
||||||
strcat(result, "/");
|
strcat(result, "/");
|
||||||
|
if (buffer[1] == '/') {
|
||||||
|
strcat(result, "/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
|
@ -67,6 +67,14 @@ int path_getrelative(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Relative paths within a server can't climb outside the server root.
|
||||||
|
* If the paths don't share server name, return the absolute path. */
|
||||||
|
if (src[0] == '/' && src[1] == '/' && last == 1) {
|
||||||
|
dst[strlen(dst) - 1] = '\0';
|
||||||
|
lua_pushstring(L, dst);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* count remaining levels in src */
|
/* count remaining levels in src */
|
||||||
count = 0;
|
count = 0;
|
||||||
for (i = last + 1; src[i] != '\0'; ++i) {
|
for (i = last + 1; src[i] != '\0'; ++i) {
|
||||||
|
@ -70,8 +70,8 @@ static void* normalize_substring(const char* str, const char* endPtr, char* writ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add to the result, filtering out duplicate slashes */
|
/* add to the result, filtering out duplicate slashes, except when they are leading slashes */
|
||||||
if (ch != '/' || last != '/') {
|
if (str == &source[1] || (ch != '/' || last != '/')) {
|
||||||
*(writePtr++) = ch;
|
*(writePtr++) = ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,10 @@
|
|||||||
test.isequal("%HOME%/user", path.getabsolute("%HOME%/user"))
|
test.isequal("%HOME%/user", path.getabsolute("%HOME%/user"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function suite.getabsolute_onServerPath()
|
||||||
|
test.isequal("//Server/Volume", path.getabsolute("//Server/Volume"))
|
||||||
|
end
|
||||||
|
|
||||||
function suite.getabsolute_onMultipleEnvVar()
|
function suite.getabsolute_onMultipleEnvVar()
|
||||||
test.isequal("$(HOME)/$(USER)", path.getabsolute("$(HOME)/$(USER)"))
|
test.isequal("$(HOME)/$(USER)", path.getabsolute("$(HOME)/$(USER)"))
|
||||||
end
|
end
|
||||||
@ -336,6 +340,10 @@
|
|||||||
test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug"))
|
test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function suite.getrelative_ReturnsChildPath_OnServerPath()
|
||||||
|
test.isequal("../Volume", path.getrelative("//Server/Shared", "//Server/Volume"))
|
||||||
|
end
|
||||||
|
|
||||||
function suite.getrelative_ReturnsAbsPath_OnDifferentDriveLetters()
|
function suite.getrelative_ReturnsAbsPath_OnDifferentDriveLetters()
|
||||||
test.isequal("D:/Files", path.getrelative("C:/Code/Premake4", "D:/Files"))
|
test.isequal("D:/Files", path.getrelative("C:/Code/Premake4", "D:/Files"))
|
||||||
end
|
end
|
||||||
@ -348,6 +356,14 @@
|
|||||||
test.isequal("/opt/include", path.getrelative("/home/me/src/project", "/opt/include"))
|
test.isequal("/opt/include", path.getrelative("/home/me/src/project", "/opt/include"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function suite.getrelative_ReturnsAbsPath_OnServerPath()
|
||||||
|
test.isequal("//Server/Volume", path.getrelative("C:/Files", "//Server/Volume"))
|
||||||
|
end
|
||||||
|
|
||||||
|
function suite.getrelative_ReturnsAbsPath_OnDifferentServers()
|
||||||
|
test.isequal("//Server/Volume", path.getrelative("//Computer/Users", "//Server/Volume"))
|
||||||
|
end
|
||||||
|
|
||||||
function suite.getrelative_ignoresExtraSlashes2()
|
function suite.getrelative_ignoresExtraSlashes2()
|
||||||
test.isequal("..", path.getrelative("/a//b/c","/a/b"))
|
test.isequal("..", path.getrelative("/a//b/c","/a/b"))
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user