Skip to content

Commit

Permalink
fix: Earmark crashes (like EarmarkParser) on "\\[{:}" #501
Browse files Browse the repository at this point in the history
* Fixes #501
  • Loading branch information
RobertDober authored Jul 11, 2024
1 parent 04a4fc4 commit d52fbbf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/earmark_parser/ast/inline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ defmodule Earmark.Parser.Ast.Inline do
if match = Regex.run(@inline_ial, src) do
[match, ial] = match
{context1, ial_attrs} = parse_attrs(context, ial, lnb)
new_tags = augment_tag_with_ial(context.value, ial_attrs)
new_tags = augment_tag_with_ial(context.value, ial_attrs, match)
{behead(src, match), lnb, set_value(context1, new_tags), use_linky?}
end
end
Expand Down
13 changes: 7 additions & 6 deletions lib/earmark_parser/helpers/ast_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ defmodule Earmark.Parser.Helpers.AstHelpers do
end

@doc false
def augment_tag_with_ial(tags, ial)

def augment_tag_with_ial([{t, a, c, m} | tags], atts) do
[{t, merge_attrs(a, atts), c, m} | tags]
def augment_tag_with_ial(tags, ial, src)
def augment_tag_with_ial([{t, a, c, m}|tags], atts, _src) do
[{t, merge_attrs(a, atts), c, m}|tags]
end

def augment_tag_with_ial([], _atts) do
def augment_tag_with_ial([], _atts, _src) do
[]
end
def augment_tag_with_ial([any], _atts, src) do
[any <> src]
end

@doc false
def code_classes(language, prefix) do
Expand Down
11 changes: 11 additions & 0 deletions test/regressions/i154_crash_on_symbolic_input_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule Test.Regressions.I154CrashOnSymbolicInputTest do
use ExUnit.Case

test "do not crash here" do
md = "\\[{:}"
html = "<p>\n[{:}</p>\n"
assert Earmark.as_html(md) == {:ok, html, []}
end

end
# SPDX-License-Identifier: Apache-2.0

0 comments on commit d52fbbf

Please sign in to comment.