Skip to content

Commit

Permalink
[Theme] Fix opening abs path if no/wrong extension (backward comp.)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveDavenport committed Aug 15, 2023
1 parent a7aa822 commit 6caaf36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
12 changes: 9 additions & 3 deletions source/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,24 +1067,30 @@ gboolean helper_execute_command(const char *wd, const char *cmd,
char *helper_get_theme_path(const char *file, const char **ext,
const char *parent_file) {

char *filename = rofi_expand_path(file);
g_debug("Opening theme, testing: %s\n", filename);
if (g_path_is_absolute(filename)) {
g_debug("Opening theme, path is absolute: %s", filename);
if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
return filename;
}
}
gboolean ext_found = FALSE;
for (const char **i = ext; *i != NULL; i++) {
if (g_str_has_suffix(file, *i)) {
ext_found = TRUE;
break;
}
}
char *filename = NULL;
if (ext_found) {
filename = rofi_expand_path(file);
} else {
g_assert_nonnull(ext[0]);
char *temp = rofi_expand_path(file);
char *temp = filename;
// TODO: Pick the first extension. needs fixing.
filename = g_strconcat(temp, ext[0], NULL);
g_free(temp);
}
g_debug("Opening theme, testing: %s\n", filename);
if (g_path_is_absolute(filename)) {
g_debug("Opening theme, path is absolute: %s", filename);
if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
Expand Down
18 changes: 5 additions & 13 deletions test/theme-parser-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,8 @@ START_TEST(test_prepare_environment_media_f) {
wid.name = "window";
wid.state = "";
setenv("QER_TEST", "true", 1);
rofi_theme_parse_string("window { width: 32; } @media( enabled: env(QER_TEST,false)){ window {width:64; }}");
rofi_theme_parse_string("window { width: 32; } @media( enabled: "
"env(QER_TEST,false)){ window {width:64; }}");
rofi_theme_parse_process_conditionals();
ck_assert_ptr_nonnull(rofi_theme);
// ck_assert_ptr_null ( rofi_theme->widgets );
Expand All @@ -1716,7 +1717,8 @@ START_TEST(test_prepare_environment_media_nf) {
widget wid;
wid.name = "window";
wid.state = "";
rofi_theme_parse_string("window { width: 32; } @media( enabled: env(QER_TEST,false)){ window {width:64; }}");
rofi_theme_parse_string("window { width: 32; } @media( enabled: "
"env(QER_TEST,false)){ window {width:64; }}");
ck_assert_ptr_nonnull(rofi_theme);
// ck_assert_ptr_null ( rofi_theme->widgets );
ck_assert_ptr_null(rofi_theme->properties);
Expand All @@ -1731,23 +1733,13 @@ END_TEST
START_TEST(test_prepare_path) {
char *current_dir = g_get_current_dir();
ck_assert_ptr_nonnull(current_dir);
char *f = rofi_theme_parse_prepare_file("../", NULL);
char *f = rofi_theme_parse_prepare_file("../");
ck_assert_ptr_nonnull(f);
ck_assert_int_eq(*f, '/');
ck_assert_str_ne(f, current_dir);
ck_assert(g_str_has_prefix(current_dir, f) == TRUE);
g_free(f);

f = rofi_theme_parse_prepare_file("../", "/tmp/");
ck_assert_ptr_nonnull(f);
ck_assert_str_eq(f, "/");
g_free(f);

f = rofi_theme_parse_prepare_file("/tmp/test.rasi", "/random/");
ck_assert_ptr_nonnull(f);
ck_assert_str_eq(f, "/tmp/test.rasi");
g_free(f);

g_free(current_dir);
}
END_TEST
Expand Down

0 comments on commit 6caaf36

Please sign in to comment.