(mc_build_filename): incorrect processing of first element of path.
If first element is relative, the result path should be also relative not absolute. If first element is empty, the result path is relative. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
b63eea10cb
Коммит
79023b26a4
@ -1006,6 +1006,7 @@ get_user_permissions (struct stat *st)
|
||||
char *
|
||||
mc_build_filename (const char *first_element, ...)
|
||||
{
|
||||
gboolean absolute;
|
||||
va_list args;
|
||||
const char *element = first_element;
|
||||
GString *path;
|
||||
@ -1017,6 +1018,8 @@ mc_build_filename (const char *first_element, ...)
|
||||
path = g_string_new ("");
|
||||
va_start (args, first_element);
|
||||
|
||||
absolute = (*first_element != '\0' && *first_element == PATH_SEP);
|
||||
|
||||
do
|
||||
{
|
||||
if (*element == '\0')
|
||||
@ -1046,7 +1049,8 @@ mc_build_filename (const char *first_element, ...)
|
||||
|
||||
va_end (args);
|
||||
|
||||
g_string_prepend_c (path, PATH_SEP);
|
||||
if (absolute)
|
||||
g_string_prepend_c (path, PATH_SEP);
|
||||
|
||||
ret = g_string_free (path, FALSE);
|
||||
canonicalize_pathname (ret);
|
||||
|
@ -54,7 +54,7 @@ START_TEST (test_mc_build_filename)
|
||||
{
|
||||
char *result;
|
||||
|
||||
check_mc_build_filename(("test", "path", NULL), "/test/path");
|
||||
check_mc_build_filename(("test", "path", NULL), "test/path");
|
||||
|
||||
check_mc_build_filename(("/test", "path/", NULL), "/test/path");
|
||||
|
||||
@ -68,6 +68,17 @@ START_TEST (test_mc_build_filename)
|
||||
|
||||
check_mc_build_filename(("/test", "path", "..", "/test", "path/", NULL), "/test/test/path");
|
||||
|
||||
check_mc_build_filename(("", "path", NULL), "path");
|
||||
|
||||
check_mc_build_filename(("", "/path", NULL), "path");
|
||||
|
||||
check_mc_build_filename(("path", "", NULL), "path");
|
||||
|
||||
check_mc_build_filename(("/path", "", NULL), "/path");
|
||||
|
||||
check_mc_build_filename(("pa", "", "th", NULL), "pa/th");
|
||||
|
||||
check_mc_build_filename(("/pa", "", "/th", NULL), "/pa/th");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user