[Xfce4-commits] <exo:xfce-4.8> Improve exo-open url and email match regexes (bug #7281).

Nick Schermer noreply at xfce.org
Mon May 9 19:56:12 CEST 2011


Updating branch refs/heads/xfce-4.8
         to 468ef59844f1e499c33d3dfeaf13b9c078690881 (commit)
       from 89c49bf73456aa4d08e6b96e3ddbf96892482927 (commit)

commit 468ef59844f1e499c33d3dfeaf13b9c078690881
Author: Nick Schermer <nick at xfce.org>
Date:   Mon May 9 18:44:35 2011 +0200

    Improve exo-open url and email match regexes (bug #7281).
    
    Regex lines were taken from the terminal.
    
    (cherry picked from commit 2c655ceaadb6d10ed17a536e0a0808e611c40531)

 exo-open/main.c |   22 +++++++++++++++++-----
 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;



More information about the Xfce4-commits mailing list