summaryrefslogtreecommitdiff
path: root/exo-open
diff options
context:
space:
mode:
authorNick Schermer <nick@xfce.org>2011-05-09 18:44:35 +0200
committerNick Schermer <nick@xfce.org>2011-05-09 18:44:35 +0200
commit2c655ceaadb6d10ed17a536e0a0808e611c40531 (patch)
tree2a54f1f2ad47f3977d90e480155088807c553bce /exo-open
parent6abf83b076f7898ed049359ea30a7477a6e69291 (diff)
downloadexo-2c655ceaadb6d10ed17a536e0a0808e611c40531.tar.gz
Improve exo-open url and email match regexes (bug #7281).
Regex lines were taken from the terminal.
Diffstat (limited to 'exo-open')
-rw-r--r--exo-open/main.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/exo-open/main.c b/exo-open/main.c
index dcece27..f2581f5 100644
--- a/exo-open/main.c
+++ b/exo-open/main.c
@@ -38,9 +38,19 @@
#include <exo/exo.h>
+#define USERCHARS "-[:alnum:]"
+#define USERCHARS_CLASS "[" USERCHARS "]"
+#define PASSCHARS_CLASS "[-[:alnum:]\\Q,?;.:/!%$^*&~\"#'\\E]"
+#define HOSTCHARS_CLASS "[-[:alnum:]]"
+#define HOST HOSTCHARS_CLASS "+(\\." HOSTCHARS_CLASS "+)*"
+#define PORT "(?:\\:[[:digit:]]{1,5})?"
+#define PATHCHARS_CLASS "[-[:alnum:]\\Q_$.+!*,;@&=?/:~#'%\\E]"
+#define PATHTERM_CLASS "[^\\Q]'.}>) \t\r\n,\"\\E]"
+#define USERPASS USERCHARS_CLASS "+(?:" PASSCHARS_CLASS "+)?"
+#define URLPATH "(?:(/"PATHCHARS_CLASS"+(?:[(]"PATHCHARS_CLASS"*[)])*"PATHCHARS_CLASS"*)*"PATHTERM_CLASS")?"
-#define MATCH_BROWSER "^(([^:/?#]+)://)?([^/?#])([^?#]*)(\\?([^#]*))?(#(.*))?"
-#define MATCH_MAILER "^[a-z0-9][a-z0-9_.-]*@[a-z0-9][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+$"
+#define MATCH_PATTERN_HTTP "(?:www|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH
+#define MATCH_PATTERN_EMAIL "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST
@@ -215,11 +225,13 @@ exo_open_find_scheme (const gchar *string)
g_free (path);
/* regular expression to check if it looks like an email address */
- if (g_regex_match_simple (MATCH_MAILER, string, G_REGEX_CASELESS, 0))
+ if (g_regex_match_simple (MATCH_PATTERN_EMAIL, string, G_REGEX_CASELESS, 0))
return g_strconcat ("mailto:", string, NULL);
- /* regular expression to check if it looks like an url */
- if (g_regex_match_simple (MATCH_BROWSER, string, G_REGEX_CASELESS, 0))
+ /* regular expression to check if it looks like an url, we don't need to check
+ * for a complete url (http://) because this is already matched by the
+ * exo_str_looks_like_an_uri() test */
+ if (g_regex_match_simple (MATCH_PATTERN_HTTP, string, G_REGEX_CASELESS, 0))
return g_strconcat ("http://", string, NULL);
return NULL;