From 4b5e6b766c61db0c77d2035b0c74a4713d9b56cd Mon Sep 17 00:00:00 2001 From: neldoreth Date: Tue, 11 May 2010 20:09:20 +0200 Subject: [PATCH] Escape filenames --- zathura.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/zathura.c b/zathura.c index 0636563..f3e1197 100644 --- a/zathura.c +++ b/zathura.c @@ -818,14 +818,25 @@ open_file(char* path, char* password) if(!password) password = (Zathura.PDF.password && strlen(Zathura.PDF.password) != 0) ? Zathura.PDF.password : NULL; - /* open file */ + /* format path */ GError* error = NULL; + char* file_uri = g_filename_to_uri(file, NULL, &error); + if (!file_uri) + { + char* message = g_strdup_printf("Can not open file: %s", error->message); + notify(ERROR, message); + g_free(message); + g_error_free(error); + return FALSE; + } + + /* open file */ g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); g_static_mutex_lock(&(Zathura.Lock.document_lock)); - Zathura.PDF.document = poppler_document_new_from_file(g_strdup_printf("file://%s", file), - password ? password : NULL, &error); + Zathura.PDF.document = poppler_document_new_from_file(file_uri, password ? password : NULL, &error); g_static_mutex_unlock(&(Zathura.Lock.document_lock)); g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + g_free(file_uri); if(!Zathura.PDF.document) {