RobertDober / earmark_parser

The Markdown to AST part of Earmark.
Apache License 2.0
68 stars 26 forks source link

[1.4.40] Parser crash on `EarmarkParser.as_ast("\\[{:}")` #154

Closed dominicletz closed 4 months ago

dominicletz commented 4 months ago

Using the EarmarkParser on the invalid md string "\\[{:}" causes a crash rather than returning an error. This is an issue for my use case where I'm using md-files to take notes and sometimes these notes contain ughly strings such as partial code fragments, backtraces and such. When finding that the parser would crash on one of my files I was able to reduce it to this minimal string causing the crash.

I don't understand the relationship between Earmark and EarmarkParser, so I've reported this issue there too: https://github.com/pragdave/earmark/issues/494

iex(2)> EarmarkParser.as_ast("\\[{:}")
** (FunctionClauseError) no function clause matching in EarmarkParser.Helpers.AstHelpers.augment_tag_with_ial/2    

    The following arguments were given to EarmarkParser.Helpers.AstHelpers.augment_tag_with_ial/2:

        # 1
        ["["]

        # 2
        %{}

    Attempted function clauses (showing 2 out of 2):

        def augment_tag_with_ial([{t, a, c, m} | tags], atts)
        def augment_tag_with_ial([], _atts)

    (earmark_parser 1.4.40) lib/earmark_parser/helpers/ast_helpers.ex:29: EarmarkParser.Helpers.AstHelpers.augment_tag_with_ial/2
    (earmark_parser 1.4.40) lib/earmark_parser/ast/inline.ex:273: EarmarkParser.Ast.Inline.converter_for_inline_ial/1
    (elixir 1.17.0) lib/enum.ex:4343: Enum.find_value_list/3
    (earmark_parser 1.4.40) lib/earmark_parser/ast/inline.ex:38: EarmarkParser.Ast.Inline._convert/4
    (earmark_parser 1.4.40) lib/earmark_parser/ast_renderer.ex:32: EarmarkParser.AstRenderer.render_block/3
    (earmark_parser 1.4.40) lib/earmark_parser/ast_renderer.ex:23: EarmarkParser.AstRenderer._render/3
    (earmark_parser 1.4.40) lib/earmark_parser.ex:622: EarmarkParser.as_ast/2
    iex:2: (file)
RobertDober commented 4 months ago

Maybe the best way to put it:

There is no relationship anymore. They have been severed, Earmark is responsible for its own parser now.

That said this is a serious bug which needs to be fixed in both projects I will report it to Earmarkas well.

RobertDober commented 4 months ago

I just released v1.4.41 which contains the fix