[evolution-data-server] evo-I#551 - Enhance URL end recognition regarding closing bracket



commit 6d08f307f35dd1d2bf9334bb75ebc98ca0a29db0
Author: Milan Crha <mcrha redhat com>
Date:   Mon Aug 19 15:37:51 2019 +0200

    evo-I#551 - Enhance URL end recognition regarding closing bracket
    
    Related to https://gitlab.gnome.org/GNOME/evolution/issues/551

 src/camel/camel-url-scanner.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/src/camel/camel-url-scanner.c b/src/camel/camel-url-scanner.c
index ed420331e..1b3dfb7d2 100644
--- a/src/camel/camel-url-scanner.c
+++ b/src/camel/camel-url-scanner.c
@@ -235,8 +235,37 @@ camel_url_pattern_end (const gchar *in,
                                 * punctuation, so strip any trailing
                                 * punctuation off. Also strip off any closing
                                 * double-quotes. */
-                               while (inptr > pos && strchr (",.:;?!-|}])\">", inptr[-1]))
+                               while (inptr > pos && strchr (",.:;?!-|}])\">", inptr[-1])) {
+                                       gchar open_bracket = 0, close_bracket = inptr[-1];
+
+                                       if (close_bracket == ')')
+                                               open_bracket = '(';
+                                       else if (close_bracket == '}')
+                                               open_bracket = '{';
+                                       else if (close_bracket == ']')
+                                               open_bracket = '[';
+                                       else if (close_bracket == '>')
+                                               open_bracket = '<';
+
+                                       if (open_bracket != 0) {
+                                               gint n_opened = 0, n_closed = 0;
+                                               const gchar *ptr;
+
+                                               for (ptr = pos; ptr < inptr; ptr++) {
+                                                       if (*ptr == open_bracket)
+                                                               n_opened++;
+                                                       else if (*ptr == close_bracket)
+                                                               n_closed++;
+                                               }
+
+                                               /* The closing bracket can match one inside the URL,
+                                                  thus keep it there. */
+                                               if (n_opened > 0 && n_opened - n_closed >= 0)
+                                                       break;
+                                       }
+
                                        inptr--;
+                               }
                        }
 
                        match->um_eo = (inptr - in);


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