logo

badwolf

Minimalist and privacy-oriented WebKitGTK+ browser
commit: 6880bf722d254d12e8236c78a7d858b9c94deee6
parent: 128c98567559d443bbb184dff247090eb5b28a8d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 29 May 2020 23:44:13 +0200

uri.c: Add support for relative paths

Diffstat:

Mpo/messages.pot4++--
Muri.c19++++++++++++++++++-
Muri_test.c5++++-
3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/po/messages.pot b/po/messages.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: Badwolf 0.5.1+gf25fc89.HEAD\n" +"Project-Id-Version: Badwolf 1.0.0+gfffd169.develop\n" "Report-Msgid-Bugs-To: contact+badwolf-msgid@hacktivis.me\n" -"POT-Creation-Date: 2020-05-18 04:14+0200\n" +"POT-Creation-Date: 2020-05-29 23:45+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" diff --git a/uri.c b/uri.c @@ -11,12 +11,29 @@ const gchar * badwolf_ensure_uri_scheme(const gchar *text, gboolean try_file) { const gchar *fallback = "about:blank"; + char *path = NULL; if(g_strcmp0(text, "") <= 0) return fallback; if(g_uri_parse_scheme(text)) return text; - if(try_file && (access(text, R_OK) == 0)) return g_strdup_printf("file://%s", text); + if(try_file) + { + path = realpath(text, NULL); + gchar *f = NULL; + + if(path != NULL) + { + if(access(path, R_OK) == 0) + { + f = g_strdup_printf("file://%s", path); + } + + free(path); + + return f; + } + } return g_strdup_printf("http://%s", text); } diff --git a/uri_test.c b/uri_test.c @@ -29,10 +29,13 @@ badwolf_ensure_uri_scheme_test(void) {fallback, "", TRUE}, {"http:///dev/null", "/dev/null", FALSE}, {"file:///dev/null", "/dev/null", TRUE}, + {"http:///usr/../dev/null", "/usr/../dev/null", FALSE}, + {"file:///dev/null", "/usr/../dev/null", TRUE}, {"http://example.org", "example.org", FALSE}, {"http://example.org", "example.org", TRUE}, {"http://", "http://", FALSE}, - {"http://", "http://", TRUE} // + {"http://", "http://", TRUE}, + {"http://badwolf.c", "badwolf.c", FALSE} // }; for(size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)