Bug 1060308: Markdown: URLs and Emails are not rendered literally in code spans and code blocks

r=glob,a=sgreen


git-svn-id: svn://10.0.0.236/trunk@265549 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bzrmirror%bugzilla.org 2014-09-05 14:45:46 +00:00
parent dfbabae10a
commit d0d83bb1c6
3 changed files with 8 additions and 3 deletions

View File

@ -1 +1 @@
9121 9122

View File

@ -1 +1 @@
cf8e842b30edbdd20fc37487d7194efbd55ff2c0 6024c5cd0553bb9884d81f3d93b78f666b433d9e

View File

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