From: Dylan William Hardison Date: Wed, 16 Jan 2019 15:29:12 +0000 (-0500) Subject: Bug 1519564 - Add a mechanism for disabling all special markdown syntax X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ecc116cc2eed6dc2a1da75913345f99abc97bc18;p=thirdparty%2Fbugzilla.git Bug 1519564 - Add a mechanism for disabling all special markdown syntax --- diff --git a/Bugzilla/Markdown.pm b/Bugzilla/Markdown.pm index 8e3c85f55..069368701 100644 --- a/Bugzilla/Markdown.pm +++ b/Bugzilla/Markdown.pm @@ -11,6 +11,7 @@ use Moo; use Encode; use Mojo::DOM; +use Mojo::Util qw(trim); use HTML::Escape qw(escape_html); use List::MoreUtils qw(any); @@ -39,11 +40,22 @@ sub _build_markdown_parser { } } +my $MARKDOWN_OFF = quotemeta '#[markdown(off)]'; sub render_html { my ($self, $markdown, $bug, $comment, $user) = @_; my $parser = $self->markdown_parser; return escape_html($markdown) unless $parser; + # This makes sure we never handle > foo text in the shortcuts code. + local $Bugzilla::Template::COLOR_QUOTES = 0; + + if ($markdown =~ /^\s*$MARKDOWN_OFF\n/s) { + my $text = $self->bugzilla_shorthand->( trim($markdown) ); + my @p = split(/\n{2,}/, $text); + my $html = join("\n", map { s/\n/
\n/gs; "

$_

\n" } @p ); + return $html; + } + no warnings 'utf8'; # this is needed because our perl is so old. # This is a bit faster since it doesn't engage the regex engine. # Replace < with \x{FDD4}, and remove \x{FDD4}. diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 1ff8e6c2d..6fbc3eeab 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -50,6 +50,7 @@ use constant FORMAT_DOUBLE => '%19s %-55s'; use constant FORMAT_2_SIZE => [19, 55]; our %SHARED_PROVIDERS; +our $COLOR_QUOTES = 1; # Pseudo-constant. sub SAFE_URL_REGEXP { @@ -216,9 +217,11 @@ sub quoteUrls { $text = html_quote($text); - # Color quoted text - $text =~ s~^(>.+)$~$1~mg; - $text =~ s~\n~\n~g; + if ($COLOR_QUOTES) { + # Color quoted text + $text =~ s~^(>.+)$~$1~mg; + $text =~ s~\n~\n~g; + } # mailto: # Use | so that $1 is defined regardless