From d65d010283193cc5ae8448adcd319c075e1a5459 Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Thu, 15 Aug 2013 01:18:29 +0200 Subject: Bug 105865: Bugzilla should pay attention to linebreaks when linkifying bug IDs in comments r=dkl a=sgreen --- Bugzilla/Template.pm | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'Bugzilla/Template.pm') diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index a8f614387..4b227e9d2 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -160,6 +160,10 @@ sub quoteUrls { my $chr1 = chr(1); $text =~ s/\0/$chr1\0/g; + # If the comment is already wrapped, we should ignore newlines when + # looking for matching regexps. Else we should take them into account. + my $s = ($comment && $comment->already_wrapped) ? qr/\s/ : qr/\h/; + # However, note that adding the title (for buglinks) can affect things # In particular, attachment matches go before bug titles, so that titles # with 'attachment 1' don't double match. @@ -226,7 +230,7 @@ sub quoteUrls { ~$1$2~igx; # attachment links - $text =~ s~\b(attachment\s*\#?\s*(\d+)(?:\s+\[details\])?) + $text =~ s~\b(attachment$s*\#?$s*(\d+)(?:$s+\[details\])?) ~($things[$count++] = get_attachment_link($2, $1, $user)) && ("\0\0" . ($count-1) . "\0\0") ~egmxi; @@ -239,43 +243,43 @@ sub quoteUrls { # Also, we can't use $bug_re?$comment_re? because that will match the # empty string my $bug_word = template_var('terms')->{bug}; - my $bug_re = qr/\Q$bug_word\E\s*\#?\s*(\d+)/i; + my $bug_re = qr/\Q$bug_word\E$s*\#?$s*(\d+)/i; my $comment_word = template_var('terms')->{comment}; - my $comment_re = qr/(?:\Q$comment_word\E|comment)\s*\#?\s*(\d+)/i; - $text =~ s~\b($bug_re(?:\s*,?\s*$comment_re)?|$comment_re) + my $comment_re = qr/(?:\Q$comment_word\E|comment)$s*\#?$s*(\d+)/i; + $text =~ s~\b($bug_re(?:$s*,?$s*$comment_re)?|$comment_re) ~ # We have several choices. $1 here is the link, and $2-4 are set # depending on which part matched (defined($2) ? get_bug_link($2, $1, { comment_num => $3, user => $user }) : "$1") - ~egox; + ~egx; # Handle a list of bug ids: bugs 1, #2, 3, 4 # Currently, the only delimiter supported is comma. # Concluding "and" and "or" are not supported. my $bugs_word = template_var('terms')->{bugs}; - my $bugs_re = qr/\Q$bugs_word\E\s*\#?\s* - \d+(?:\s*,\s*\#?\s*\d+)+/ix; - while ($text =~ m/($bugs_re)/go) { + my $bugs_re = qr/\Q$bugs_word\E$s*\#?$s* + \d+(?:$s*,$s*\#?$s*\d+)+/ix; + while ($text =~ m/($bugs_re)/g) { my $offset = $-[0]; my $length = $+[0] - $-[0]; my $match = $1; - $match =~ s/((?:#\s*)?(\d+))/get_bug_link($2, $1);/eg; + $match =~ s/((?:#$s*)?(\d+))/get_bug_link($2, $1);/eg; # Replace the old string with the linkified one. substr($text, $offset, $length) = $match; } my $comments_word = template_var('terms')->{comments}; - my $comments_re = qr/(?:comments|\Q$comments_word\E)\s*\#?\s* - \d+(?:\s*,\s*\#?\s*\d+)+/ix; - while ($text =~ m/($comments_re)/go) { + my $comments_re = qr/(?:comments|\Q$comments_word\E)$s*\#?$s* + \d+(?:$s*,$s*\#?$s*\d+)+/ix; + while ($text =~ m/($comments_re)/g) { my $offset = $-[0]; my $length = $+[0] - $-[0]; my $match = $1; - $match =~ s|((?:#\s*)?(\d+))|$1|g; + $match =~ s|((?:#$s*)?(\d+))|$1|g; substr($text, $offset, $length) = $match; } -- cgit v1.2.3-24-g4f1b