[gnome-terminal] regex: Allow balanced pairs of square brackets in URLs



commit e6b08d49b17b372dfd86a1e7116ea4fc59c086e4
Author: Egmont Koblinger <egmont gmail com>
Date:   Sun Dec 17 23:33:10 2017 +0100

    regex: Allow balanced pairs of square brackets in URLs
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763980#c8

 src/terminal-regex.c |    7 +++++++
 src/terminal-regex.h |    6 +++---
 2 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/src/terminal-regex.c b/src/terminal-regex.c
index 250c0eb..33f8ec9 100644
--- a/src/terminal-regex.c
+++ b/src/terminal-regex.c
@@ -220,6 +220,13 @@ main (int argc, char **argv)
   assert_match_anchored (DEFS URLPATH, "/().", "/()");
   assert_match_anchored (DEFS URLPATH, "/", ENTIRE);
   assert_match_anchored (DEFS URLPATH, "", ENTIRE);
+  assert_match_anchored (DEFS URLPATH, "/php?param[]=value1&param[]=value2", ENTIRE);
+  assert_match_anchored (DEFS URLPATH, "/foo?param1[index1]=value1&param2[index2]=value2", ENTIRE);
+  assert_match_anchored (DEFS URLPATH, "/[[[]][]]", ENTIRE);
+  assert_match_anchored (DEFS URLPATH, "/[([])]([()])", ENTIRE);
+  assert_match_anchored (DEFS URLPATH, "/([()])[([])]", ENTIRE);
+  assert_match_anchored (DEFS URLPATH, "/[(])", "/");
+  assert_match_anchored (DEFS URLPATH, "/([)]", "/");
 
 
   /* Put the components together and test the big picture */
diff --git a/src/terminal-regex.h b/src/terminal-regex.h
index ddf75e0..5ca2f22 100644
--- a/src/terminal-regex.h
+++ b/src/terminal-regex.h
@@ -126,10 +126,10 @@
 /* Chars to end a URL */
 #define PATHTERM_CLASS "[-[:alnum:]\\Q_$+*:;@&=/~#|%\\E]"
 
-/* Recursive definition of PATH that allows parentheses only if balanced, see bug 763980. */
-#define PATH_INNER_DEF "(?(DEFINE)(?<PATH_INNER>(?x: (?: " PATHCHARS_CLASS "* \\( (?&PATH_INNER) \\) )* " 
PATHCHARS_CLASS "* )))"
+/* Recursive definition of PATH that allows parentheses and square brackets only if balanced, see bug 
763980. */
+#define PATH_INNER_DEF "(?(DEFINE)(?<PATH_INNER>(?x: (?: " PATHCHARS_CLASS "* (?: \\( (?&PATH_INNER) \\) | 
\\[ (?&PATH_INNER) \\] ) )* " PATHCHARS_CLASS "* )))"
 /* Same as above, but the last character (if exists and is not a parenthesis) must be from PATHTERM_CLASS. */
-#define PATH_DEF "(?(DEFINE)(?<PATH>(?x: (?: " PATHCHARS_CLASS "* \\( (?&PATH_INNER) \\) )* (?: " 
PATHCHARS_CLASS "* " PATHTERM_CLASS " )? )))"
+#define PATH_DEF "(?(DEFINE)(?<PATH>(?x: (?: " PATHCHARS_CLASS "* (?: \\( (?&PATH_INNER) \\) | \\[ 
(?&PATH_INNER) \\] ) )* (?: " PATHCHARS_CLASS "* " PATHTERM_CLASS " )? )))"
 
 #define URLPATH "(?x: /(?&PATH) )?"
 #define VOIP_PATH "(?x: [;?](?&PATH) )?"


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