diff --git a/lib/earmark/line_scanner.ex b/lib/earmark/line_scanner.ex index 8d76c90b..51814cd4 100644 --- a/lib/earmark/line_scanner.ex +++ b/lib/earmark/line_scanner.ex @@ -155,7 +155,11 @@ defmodule Earmark.LineScanner do [_, tag] = match %Line.HtmlOpenTag{tag: tag, content: line, indent: 0} - match = !recursive && Regex.run(~r/\A(\s{0,3})<\/([-\w]+?)>/, line) -> + # Is there potential for a DoS attack here, must check this match against + # input like: + # "a\z/, line) -> [_, leading_spaces, tag] = match %Line.HtmlCloseTag{tag: tag, indent: String.length(leading_spaces)} diff --git a/test/acceptance/ast/html/block_test.exs b/test/acceptance/ast/html/block_test.exs index 5d1b8544..fb05f616 100644 --- a/test/acceptance/ast/html/block_test.exs +++ b/test/acceptance/ast/html/block_test.exs @@ -226,9 +226,16 @@ defmodule Acceptance.Ast.Html.BlockTest do assert as_ast(markdown) == {:error, ast, messages} end - test "however, this closes and keeps the garbage" do + test "new rule (tribute to, you know...) closing tag must be last one, but it ain't necessarily so (yet another tribute)" do markdown = "
\nline\n
" - ast = [{"div", [], ["line"], @verbatim}, ""] + ast = [{"div", '', ["line"], %{meta: %{verbatim: true}}}, ""] + messages = [{:warning, 1, "Failed to find closing
"}] + + assert as_ast(markdown) == {:error, ast, messages} + end + test "new rule (tribute to, you know...) closing tag must be last one, and is" do + markdown = "
\nline\n
" + ast = [{"div", [], ["line", ""], @verbatim}] messages = [] assert as_ast(markdown) == {:ok, ast, messages}