commit 50b674a0cf199226abebe238a2ce582d7d7b96bb
parent 2a379c6177220603187ce8c2acaa1d946d27d0cb
Author: Kyle Milz <kmilz@ucalgary.ca>
Date: Fri, 19 Oct 2012 22:39:42 -0600
utilities: make uri_sanitize() a bit smarter
Diffstat:
1 file changed, 17 insertions(+), 25 deletions(-)
diff --git a/src/utilities.c b/src/utilities.c
@@ -801,36 +801,28 @@ make_bf_list(Evas_Object *label, Buffer_Data *bd)
const char*
uri_sanitize(const char *uri)
{
- char *fixed_uri;
- char *schema;
- char *tmp;
+ char *tmp, *spaces;
+ int len;
+ Eina_Strbuf *buf = eina_strbuf_new();
+
+ printf("uri_sanitize() url = \"%s\"\n", uri);
if (!uri || !*uri) return NULL;
/* TODO: strip whitespace, different search engines */
+ len = strlen(uri);
tmp = strstr(uri, "://");
- if (!tmp || (tmp == uri) || (tmp > (uri + 15))) {
- char *new_uri = NULL;
- if (ecore_file_exists(uri)) {
- schema = "file";
- new_uri = ecore_file_realpath(uri);
- }
- else
- schema = "http";
-
- if (asprintf(&fixed_uri, "%s://%s", schema, new_uri ? new_uri : uri) > 0) {
- free(new_uri);
- return fixed_uri;
- }
- free(new_uri);
- }
- else {
- Eina_Strbuf *search_url = eina_strbuf_new();
- eina_strbuf_append(search_url, "http://google.com/search?q=");
- eina_strbuf_append(search_url, uri);
- return eina_strbuf_string_steal(search_url);
- }
+ spaces = strchr(uri, ' ');
+
+ if (len > 3 && tmp)
+ eina_strbuf_append(buf, uri);
+ else if (ecore_file_exists(uri))
+ eina_strbuf_append_printf(buf, "file://%s", uri);
+ else if (spaces || !strchr(uri, '.'))
+ eina_strbuf_append_printf(buf, "https://duckduckgo.com/html/?q=%s", uri);
+ else
+ eina_strbuf_append_printf(buf, "http://%s", uri);
- return NULL;
+ return eina_strbuf_string_steal(buf);
}