From: Daniel Carl Date: Thu, 21 Feb 2013 19:34:37 +0000 (+0100) Subject: Check if uri is a file path before open it. X-Git-Url: https://git.owens.tech/git.owens.tech/git.owens.tech/git?a=commitdiff_plain;h=74d94e48d248b162929e5d44a8a41ee993aa841b;p=vimb.git Check if uri is a file path before open it. --- diff --git a/config.mk b/config.mk index 1f06e1f..a3ad6a4 100644 --- a/config.mk +++ b/config.mk @@ -39,7 +39,7 @@ LDFLAGS += $(shell pkg-config --libs $(LIBS)) -lX11 -lXext CPPFLAGS += -DFEATURE_COOKIE CPPFLAGS += -DFEATURE_SEARCH_HIGHLIGHT -CPPFLAGS += -DVERSION=\"${VERSION}\" +CPPFLAGS += -DVERSION=\"${VERSION}\" -D_BSD_SOURCE ifeq ($(USEGTK3), 1) CPPFLAGS += -DHAS_GTK3 endif diff --git a/src/main.c b/src/main.c index c8ee0b3..fa47b68 100644 --- a/src/main.c +++ b/src/main.c @@ -309,18 +309,24 @@ static gboolean vp_process_input(const char* input) gboolean vp_load_uri(const Arg* arg) { char* uri; - char* line = arg->s; + char* path = arg->s; - if (!line) { + if (!path) { return FALSE; } - g_strstrip(line); - if (!strlen(line)) { + g_strstrip(path); + if (!strlen(path)) { return FALSE; } - uri = g_strrstr(line, "://") ? g_strdup(line) : g_strdup_printf("http://%s", line); + /* check if the path is a file path */ + if (path[0] == '/' || !strcspn(path, "./")) { + char* rp = realpath(path, NULL); + uri = g_strdup_printf("file://%s", rp); + } else { + uri = g_strrstr(path, "://") ? g_strdup(path) : g_strdup_printf("http://%s", path); + } if (arg->i == VP_TARGET_NEW) { char *argv[64]; diff --git a/src/main.h b/src/main.h index 020f956..f35ebea 100644 --- a/src/main.h +++ b/src/main.h @@ -20,6 +20,7 @@ #ifndef _MAIN_H #define _MAIN_H +#include #include #include #include