Commit d65d0102 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 105865: Bugzilla should pay attention to linebreaks when linkifying bug IDs in comments

r=dkl a=sgreen
parent 37ce30c4
......@@ -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 {
~<a href=\"mailto:$2\">$1$2</a>~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 }) :
"<a href=\"$current_bugurl#c$4\">$1</a>")
~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+))|<a href="$current_bugurl#c$2">$1</a>|g;
$match =~ s|((?:#$s*)?(\d+))|<a href="$current_bugurl#c$2">$1</a>|g;
substr($text, $offset, $length) = $match;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment