]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1060308: Markdown: URLs and Emails are not rendered literally in code spans and...
authorKoosha KM <koosha.khajeh@gmail.com>
Fri, 5 Sep 2014 14:37:03 +0000 (14:37 +0000)
committerDavid Lawrence <dkl@mozilla.com>
Fri, 5 Sep 2014 14:37:03 +0000 (14:37 +0000)
r=glob,a=sgreen

Bugzilla/Markdown.pm

index c5a34fb6e18480a590ffd9ca65271aa1c84d5c4f..6cbe0f6c4898df9468982ed88518ee44462d4a9b 100644 (file)
@@ -47,6 +47,7 @@ our %g_escape_table;
 foreach my $char (split //, '\\`*_{}[]()>#+-.!~') {
     $g_escape_table{$char} = md5_hex($char);
 }
+$g_escape_table{'&lt;'} = md5_hex('&lt;');
 
 sub new {
     my $invocant = shift;
@@ -149,7 +150,7 @@ sub _StripLinkDefinitions {
 sub _DoAutoLinks {
     my ($self, $text) = @_;
 
-    $text =~ s{(?:<|&lt;)((?:https?|ftp):[^'">\s]+)(?:>|&gt;)}{<a href="$1">$1</a>}gi;
+    $text =~ s{(?:<|&lt;)((?:https?|ftp):[^'">\s]+?)(?:>|&gt;)}{<a href="$1">$1</a>}gi;
     return $text;
 }
 
@@ -406,8 +407,11 @@ sub _EncodeCode {
     # In other words, html_quote() will change '&gt;' to '&amp;gt;' and then we will
     # change '&amp;gt' -> '&gt;' -> '>' if we write this substitution as the first one.
     $text =~ s/&amp;/&/g;
+    $text =~ s{<a \s+ href="(?:mailto:)? (.+?)"> \1 </a>}{$1}xmgi;
     $text = $self->SUPER::_EncodeCode($text);
     $text =~ s/~/$g_escape_table{'~'}/go;
+    # Encode '&lt;' to prevent URLs from getting linkified in code spans
+    $text =~ s/&lt;/$g_escape_table{'&lt;'}/go;
 
     return $text;
 }
@@ -426,6 +430,7 @@ sub _UnescapeSpecialChars {
 
     $text = $self->SUPER::_UnescapeSpecialChars($text);
     $text =~ s/$g_escape_table{'~'}/~/go;
+    $text =~ s/$g_escape_table{'&lt;'}/&lt;/go;
 
     return $text;
 }