From e55bef366b87ecbcb66c93669f41876afc1d2446 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 18 Apr 2019 23:49:42 +0000 Subject: linkify: require parentheses pairs in URLs Dangling parentheses with trailing punctuation usually means the parentheses is not intended as part of the URL. --- lib/PublicInbox/Linkify.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/Linkify.pm b/lib/PublicInbox/Linkify.pm index 71193bc2..d4778e7d 100644 --- a/lib/PublicInbox/Linkify.pm +++ b/lib/PublicInbox/Linkify.pm @@ -47,8 +47,16 @@ sub linkify_1 { if ($url =~ s/$re//) { $end = $1; } - } elsif ($url =~ s/([\.,;])\z//) { - $end = $1; + } elsif ($url =~ s/(\))?([\.,;])\z//) { + $end = $2; + # require ')' to be paired with '(' + if (defined $1) { # ')' + if (index($url, '(') < 0) { + $end = ")$end"; + } else { + $url .= ')'; + } + } } elsif ($url !~ /\(/ && $url =~ s/\)\z//) { $end = ')'; } -- cgit v1.2.3-24-ge0c7