Skip to content

Commit

Permalink
Refs: #356;
Browse files Browse the repository at this point in the history
We'll keep it here from now, as in 1.5 this might become obsolete due to #358
  • Loading branch information
RobertDober committed Jun 22, 2020
1 parent 5dc97a6 commit b6606e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/earmark/line_scanner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ 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</x</x</x</x ..." will it back up n time or is it clever enough
# to check for a match at the end first?
# Does not look like it, but who knows
match = !recursive && Regex.run(~r/\A(\s{0,3}).*<\/([-\w]+)>.*\z/, line) ->
[_, leading_spaces, tag] = match
%Line.HtmlCloseTag{tag: tag, indent: String.length(leading_spaces)}

Expand Down
11 changes: 9 additions & 2 deletions test/acceptance/ast/html/block_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<div>\nline\n</div><hello>"
ast = [{"div", [], ["line"], @verbatim}, "<hello>"]
ast = [{"div", '', ["line"], %{meta: %{verbatim: true}}}, "<hello>"]
messages = [{:warning, 1, "Failed to find closing <div>"}]

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 = "<div>\nline\n</hello></div>"
ast = [{"div", [], ["line", "</hello>"], @verbatim}]
messages = []

assert as_ast(markdown) == {:ok, ast, messages}
Expand Down

0 comments on commit b6606e6

Please sign in to comment.