1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Allow trailing / for relative paths in strPathAbsolute().

The trailing / does nothing but is nevertheless valid syntax.
This commit is contained in:
David Steele 2019-11-15 08:53:15 -05:00
parent 83ab272171
commit 48e8942e86
2 changed files with 12 additions and 1 deletions

View File

@ -635,8 +635,18 @@ strPathAbsolute(const String *this, const String *base)
{
const String *pathPart = strLstGet(pathList, 0);
// If the last part is empty
if (strSize(pathPart) == 0)
{
// Allow when this is the last part since it just means there was a trailing /
if (strLstSize(pathList) == 1)
{
strLstRemoveIdx(pathList, 0);
break;
}
THROW_FMT(AssertError, "'%s' is not a valid relative path", strPtr(this));
}
if (strEq(pathPart, DOTDOT_STR))
{

View File

@ -78,9 +78,10 @@ testRun(void)
TEST_ERROR(strPathAbsolute(STRDEF(".."), STRDEF("path1")), AssertError, "base path 'path1' is not absolute");
TEST_ERROR(
strPathAbsolute(STRDEF(".."), STRDEF("/")), AssertError, "relative path '..' goes back too far in base path '/'");
TEST_ERROR(strPathAbsolute(STRDEF("path1/"), STRDEF("/")), AssertError, "'path1/' is not a valid relative path");
TEST_ERROR(strPathAbsolute(STRDEF("path1//"), STRDEF("/")), AssertError, "'path1//' is not a valid relative path");
TEST_RESULT_STR_Z(strPathAbsolute(STRDEF("/"), NULL), "/", "path is already absolute");
TEST_RESULT_STR_Z(strPathAbsolute(STRDEF(".."), STRDEF("/path1")), "/", "simple relative path");
TEST_RESULT_STR_Z(strPathAbsolute(STRDEF("../"), STRDEF("/path1")), "/", "simple relative path with trailing /");
TEST_RESULT_STR_Z(
strPathAbsolute(STRDEF("../path2/../path3"), STRDEF("/base1/base2")), "/base1/path3", "complex relative path");
}