From 74d94e48d248b162929e5d44a8a41ee993aa841b Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Thu, 21 Feb 2013 20:34:37 +0100
Subject: [PATCH] Check if uri is a file path before open it.

---
 config.mk  |  2 +-
 src/main.c | 16 +++++++++++-----
 src/main.h |  1 +
 3 files changed, 13 insertions(+), 6 deletions(-)

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 <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <webkit/webkit.h>
-- 
2.20.1