Check if uri is a file path before open it.
authorDaniel Carl <danielcarl@gmx.de>
Thu, 21 Feb 2013 19:34:37 +0000 (20:34 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Thu, 21 Feb 2013 19:34:37 +0000 (20:34 +0100)
config.mk
src/main.c
src/main.h

index 1f06e1f..a3ad6a4 100644 (file)
--- 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
index c8ee0b3..fa47b68 100644 (file)
@@ -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];
 
index 020f956..f35ebea 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef _MAIN_H
 #define _MAIN_H
 
+#include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <webkit/webkit.h>