diff options
3 files changed, 24 insertions, 4 deletions
| -rw-r--r-- | po/messages.pot | 4 | ||||
| -rw-r--r-- | uri.c | 19 | ||||
| -rw-r--r-- | uri_test.c | 5 |
diff --git a/po/messages.pot b/po/messages.pot index 115f3b4..8b30b0d 100644 --- 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" @@ -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); } @@ -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++) |