diff options
author | Diogo Sousa <diogogsousa@gmail.com> | 2013-10-21 04:25:36 +0100 |
---|---|---|
committer | TingPing <tingping@tingping.se> | 2013-10-22 13:28:03 -0400 |
commit | 6d3c176ff83052f35c0eed2ffd7aa35bf69315fb (patch) | |
tree | 2d1aa9b512f6313ccc2b05cce27674e73dd66937 | |
parent | a25363f5c35ba818b2dcd6abc4b7375d6fd41770 (diff) |
url_check_line () now recognizes all urls
previously it only recognized url with "://" after the scheme. Urls without a scheme are purposely not recognized by this function. Fixes #701 Closes #815
-rw-r--r-- | src/common/url.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/common/url.c b/src/common/url.c index a28999d2..baf0e4a2 100644 --- a/src/common/url.c +++ b/src/common/url.c @@ -35,6 +35,7 @@ GTree *url_btree = NULL; static gboolean regex_match (const GRegex *re, const char *word, int *start, int *end); static const GRegex *re_url (void); +static const GRegex *re_url_no_scheme (void); static const GRegex *re_host (void); static const GRegex *re_host6 (void); static const GRegex *re_email (void); @@ -294,7 +295,10 @@ match_email (const char *word, int *start, int *end) static gboolean match_url (const char *word, int *start, int *end) { - return regex_match (re_url (), word, start, end); + if (regex_match (re_url (), word, start, end)) + return TRUE; + + return regex_match (re_url_no_scheme (), word, start, end); } static gboolean @@ -372,8 +376,7 @@ url_check_line (char *buf, int len) g_match_info_fetch_pos(gmi, 0, &start, &end); while (end > start && (po[end - 1] == '\r' || po[end - 1] == '\n')) end--; - if (g_strstr_len (po + start, end - start, "://")) - url_add(po + start, end - start); + url_add(po + start, end - start); g_match_info_next(gmi, NULL); } g_match_info_free(gmi); @@ -540,6 +543,18 @@ struct }; static const GRegex * +re_url_no_scheme (void) +{ + static GRegex *url_ret = NULL; + + if (url_ret) return url_ret; + + url_ret = make_re ("(" HOST_URL OPT_PORT "/" "(" PATH ")?" ")"); + + return url_ret; +} + +static const GRegex * re_url (void) { static GRegex *url_ret = NULL; @@ -551,12 +566,12 @@ re_url (void) grist_gstr = g_string_new (NULL); - /* Add regex "host/path", representing a "schemeless" url */ - g_string_append (grist_gstr, "(" HOST_URL OPT_PORT "/" "(" PATH ")?" ")"); - for (i = 0; uri[i].scheme; i++) { - g_string_append (grist_gstr, "|("); + if (i) + g_string_append (grist_gstr, "|"); + + g_string_append (grist_gstr, "("); g_string_append_printf (grist_gstr, "%s:", uri[i].scheme); if (uri[i].flags & URI_AUTHORITY) |