commit c5b329db6d83c5f1f9b5926d6aad4c05602d88e7
Author: Jan Gerber <j@mailb.org>
Date:   Thu Aug 28 23:45:58 2014 +0200

    Match urls with IPv6 addresses and other corner cases
    
    http://[2a00:1450:400d:802::1004]/
    http://[::1]/ (localhost)
    http://[::1]:8000/
    http://aa.bb/c
    http://aa.bb/

diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index ad78388..31be3da 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -154,17 +154,19 @@ static void terminal_screen_set_override_command (TerminalScreen  *screen,
 
 static guint signals[LAST_SIGNAL];
 
-#define USERCHARS "-[:alnum:]"
+#define USERCHARS "-[:alnum:]\\Q_.+\\E"
 #define USERCHARS_CLASS "[" USERCHARS "]"
 #define PASSCHARS_CLASS "[-[:alnum:]\\Q,?;.:/!%$^*&~\"#'\\E]"
 #define HOSTCHARS_CLASS "[-[:alnum:]]"
-#define HOST HOSTCHARS_CLASS "+(\\." HOSTCHARS_CLASS "+)*"
+#define HOSTNAME HOSTCHARS_CLASS "+(?:\\." HOSTCHARS_CLASS "+)*"
+#define IPV6ADDRESS "\\[(?:[[:xdigit:]]{0,4}:){2,7}[[:xdigit:]]{0,4}\\]"
+#define HOST "(?:" HOSTNAME "|" IPV6ADDRESS ")"
 #define PORT "(?:\\:[[:digit:]]{1,5})?"
 #define PATHCHARS_CLASS "[-[:alnum:]\\Q_$.+!*,:;@&=?/~#%\\E]"
-#define PATHTERM_CLASS "[^\\Q]'.:}>) \t\r\n,\"\\E]"
+#define PATHTERM_CLASS "[[:alnum:]\\Q_$+*@&=/~#%\\E]"
 #define SCHEME "(?:news:|telnet:|nntp:|file:\\/|https?:|ftps?:|sftp:|webcal:)"
 #define USERPASS USERCHARS_CLASS "+(?:" PASSCHARS_CLASS "+)?"
-#define URLPATH   "(?:(/"PATHCHARS_CLASS"+(?:[(]"PATHCHARS_CLASS"*[)])*"PATHCHARS_CLASS"*)*"PATHTERM_CLASS")?"
+#define URLPATH "(?:(?:\\(" PATHCHARS_CLASS "*\\)|" PATHCHARS_CLASS ")*(?:\\(" PATHCHARS_CLASS "*\\)|" PATHTERM_CLASS "))?"
 
 typedef struct {
   const char *pattern;
@@ -174,7 +176,7 @@ typedef struct {
 
 static const TerminalRegexPattern url_regex_patterns[] = {
   { SCHEME "//(?:" USERPASS "\\@)?" HOST PORT URLPATH, FLAVOR_AS_IS, G_REGEX_CASELESS },
-  { "(?:www|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH , FLAVOR_DEFAULT_TO_HTTP, G_REGEX_CASELESS  },
+  { "(?:www[[:digit:]]{0,3}|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH, FLAVOR_DEFAULT_TO_HTTP, G_REGEX_CASELESS },
   { "(?:callto:|h323:|sip:)" USERCHARS_CLASS "[" USERCHARS ".]*(?:" PORT "/[a-z0-9]+)?\\@" HOST, FLAVOR_VOIP_CALL, G_REGEX_CASELESS  },
   { "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, FLAVOR_EMAIL, G_REGEX_CASELESS  },
   { "(?:news:|man:|info:)[-[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+", FLAVOR_AS_IS, G_REGEX_CASELESS  },
