diff --git a/Markdown.pl b/Markdown.pl index c8edebd..e7299cb 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -568,6 +568,9 @@ sub Markdown { $text .= "\n" unless $text eq ""; + # Sanitize all '<'...'>' tags if requested + $text = _SanitizeTags($text) if $opt{sanitize}; + utf8::encode($text); if (defined($opt{h1}) && $opt{h1} ne "" && ref($_[0]) eq "HASH") { utf8::encode($opt{h1}); @@ -2189,16 +2192,58 @@ sub _DoTag { if (($tag =~ m{^<($g_possible_tag_name)(?:[\s>]|/>$)} || $tag =~ m{^}) && $ok_tag_name{lc($1)}) { - $tag = _Sanitize($tag) if $opt{sanitize}; return _ProcessURLTag("href", $tag) if $tag =~ /^' tags in the input and HTML encode those things +# that cannot possibly be tags and at the same time sanitize them. +# +# $1 => text to process +# <= sanitized text +sub _SanitizeTags { + my $text = shift; + my $ans = ""; + my $end = length($text); + pos($text) = 0; + while (pos($text) < $end) { + if ($text =~ /\G([^<]+)/gc) { + $ans .= $1; + next; + } + if ($text =~ /\G(<[^>]*>)/gc) { + my $tag = $1; + if ($tag =~ /^