[gnome-terminal] screen: Rewrite URL regexes



commit 0c9a82e762135437faf591d9c53d056133da4c03
Author: Egmont Koblinger <egmont gmail com>
Date:   Sun Feb 21 15:37:01 2016 +0100

    screen: Rewrite URL regexes
    
    Rewrite the URL match regex to be more correct.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756038

 src/Makefile.am       |   27 +++++++++++++++++++++++++++
 src/terminal-screen.c |   33 ++++++++++-----------------------
 2 files changed, 37 insertions(+), 23 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3e5315b..17f55e9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,6 +6,8 @@ bin_PROGRAMS = gnome-terminal
 libexec_PROGRAMS = gnome-terminal-server
 noinst_PROGRAMS =
 
+check_PROGRAMS = terminal-regex
+
 if WITH_NAUTILUS_EXTENSION
 nautilusextension_LTLIBRARIES = libterminal-nautilus.la
 endif # WITH_NAUTILUS_EXTENSION
@@ -61,6 +63,7 @@ gnome_terminal_server_SOURCES = \
        terminal-prefs.h \
        terminal-profiles-list.c \
        terminal-profiles-list.h \
+       terminal-regex.h \
        terminal-schemas.h \
        terminal-settings-list.c \
        terminal-settings-list.h \
@@ -150,6 +153,30 @@ terminal-gdbus-generated.c terminal-gdbus-generated.h: org.gnome.Terminal.xml Ma
 terminal-resources.h terminal-resources.c: terminal.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) 
--generate-dependencies --sourcedir $(srcdir) $(srcdir)/terminal.gresource.xml)
        $(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) --generate 
--c-name terminal $<
 
+# Checks
+
+TESTS = \
+       terminal-regex \
+       $(NULL)
+
+# Check programmes
+
+terminal_regex_CPPFLAGS = \
+       $(AM_CPPFLAGS)
+terminal_regex_SOURCES = \
+       terminal-regex.c \
+       terminal-regex.h \
+       $(NULL)
+terminal_regex_CFLAGS = \
+       -DTERMINAL_REGEX_MAIN \
+       $(TERM_CFLAGS) \
+       $(WARN_CFLAGS) \
+       $(AM_CFLAGS)
+terminal_regex_LDFLAGS = \
+       $(AM_LDFLAGS)
+terminal_regex_LDADD = \
+       $(TERM_LIBS)
+
 # Terminal client
 
 if ENABLE_GTERMINAL
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 97854ad..33a34ab 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -23,6 +23,7 @@
 #include "terminal-pcre2.h"
 #endif
 
+#include "terminal-regex.h"
 #include "terminal-screen.h"
 
 #include <errno.h>
@@ -165,34 +166,22 @@ static void terminal_screen_set_override_command (TerminalScreen  *screen,
 
 static guint signals[LAST_SIGNAL];
 
-#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 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")?"
-
 typedef struct {
   const char *pattern;
   TerminalURLFlavor flavor;
-  gboolean caseless;
 } TerminalRegexPattern;
 
 static const TerminalRegexPattern url_regex_patterns[] = {
-  { SCHEME "//(?:" USERPASS "\\@)?" HOST PORT URLPATH, FLAVOR_AS_IS, TRUE },
-  { "(?:www|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH , FLAVOR_DEFAULT_TO_HTTP, TRUE  },
-  { "(?:callto:|h323:|sip:)" USERCHARS_CLASS "[" USERCHARS ".]*(?:" PORT "/[a-z0-9]+)?\\@" HOST, 
FLAVOR_VOIP_CALL, TRUE },
-  { "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, FLAVOR_EMAIL, TRUE },
-  { "(?:news:|man:|info:)[-[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+", FLAVOR_AS_IS, TRUE },
+  { REGEX_URL_AS_IS, FLAVOR_AS_IS },
+  { REGEX_URL_HTTP,  FLAVOR_DEFAULT_TO_HTTP },
+  { REGEX_URL_FILE,  FLAVOR_AS_IS },
+  { REGEX_URL_VOIP,  FLAVOR_VOIP_CALL },
+  { REGEX_EMAIL,     FLAVOR_EMAIL },
+  { REGEX_NEWS_MAN,  FLAVOR_AS_IS },
 };
 
 static const TerminalRegexPattern extra_regex_patterns[] = {
-  { "(0[Xx][[:xdigit:]]+|[[:digit:]]+)", FLAVOR_NUMBER, FALSE },
+  { "(0[Xx][[:xdigit:]]+|[[:digit:]]+)", FLAVOR_NUMBER },
 };
 
 #ifdef WITH_PCRE2
@@ -256,8 +245,7 @@ precompile_regexes (const TerminalRegexPattern *regex_patterns,
 
 #ifdef WITH_PCRE2
       (*regexes)[i] = vte_regex_new (regex_patterns[i].pattern, -1,
-                                     PCRE2_UTF | PCRE2_NO_UTF_CHECK | PCRE2_MULTILINE |
-                                     (regex_patterns[i].caseless ? PCRE2_CASELESS : 0),
+                                     PCRE2_UTF | PCRE2_NO_UTF_CHECK | PCRE2_MULTILINE,
                                      &error);
       g_assert_no_error (error);
 
@@ -269,8 +257,7 @@ precompile_regexes (const TerminalRegexPattern *regex_patterns,
 #else
       (*regexes)[i] = g_regex_new (regex_patterns[i].pattern,
                                    G_REGEX_OPTIMIZE |
-                                   G_REGEX_MULTILINE |
-                                   (regex_patterns[i].caseless ? G_REGEX_CASELESS : 0),
+                                   G_REGEX_MULTILINE,
                                    0, &error);
       g_assert_no_error (error);
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]