From ff7fb525fc768d5be0d1ca232dce5f0e0461bd07 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 12 Feb 2021 10:18:39 -0700 Subject: [PATCH] Markdown.pl: avoid accidentally nested anchors Given something that looks like this: [1][] [1]: https://example.com/ Ever since commit dfbf2b4e304eb9c0663f66d6ec6d85b5dfdf8230 ("Markdown.pl: retain square brackets around footnotes", 2017-01-19, markdown_1.1.2), the link text has been rendered to include the surrounding '[' and ']' because it just looks better that way and produces a bigger link target. Unfortunately that can result in the linked text being processed again and producing a nexted anchor which is not only invalid according to the XHTML specification but is also the wrong rendering for the input. Deal with this by hiding the '[' and ']' characters inside link text the same way other characters within the link text are already being hidden. Signed-off-by: Kyle J. McKay --- Markdown.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Markdown.pl b/Markdown.pl index 0ddb0b2..40f66c1 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -1583,8 +1583,8 @@ sub _MakeATag { $text =~ s{<(/?a)}{<$1}sogi; $text = _DoItalicsAndBoldAndStrike($text); # We've got to encode any of these remaining to avoid - # conflicting with other italics, bold and strike through. - $text =~ s!([*_~])!$g_escape_table{$1}!g; + # conflicting with other italics, bold and strike through and links. + $text =~ s!([]*_~[])!$g_escape_table{$1}!g; $result .= " title=\"" . _EncodeAttText($title) . "\"" if $title ne ""; return $result . $g_escape_table{'>'} . $text . $g_escape_table{'<'}."/a".$g_escape_table{'>'};