pragdave / earmark

Markdown parser for Elixir
Other
859 stars 135 forks source link

[1.4.46] Parser crash on `Earmark.as_ast("\\[{:}")` #494

Closed dominicletz closed 2 months ago

dominicletz commented 2 months ago

Using Earmark for displaying .md files I found that there are certain md files that cause the parser to crash. Reducing the files to the minimum I found the minimal string to reproduce the crash is this:

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

    The following arguments were given to Earmark.Parser.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 1.4.46) lib/earmark_parser/helpers/ast_helpers.ex:29: Earmark.Parser.Helpers.AstHelpers.augment_tag_with_ial/2
    (earmark 1.4.46) lib/earmark_parser/ast/inline.ex:258: Earmark.Parser.Ast.Inline.converter_for_inline_ial/1
    (elixir 1.14.5) lib/enum.ex:4239: Enum.find_value_list/3
    (earmark 1.4.46) lib/earmark_parser/ast/inline.ex:36: Earmark.Parser.Ast.Inline._convert/4
    (earmark 1.4.46) lib/earmark_parser/ast_renderer.ex:32: Earmark.Parser.AstRenderer.render_block/3
    (earmark 1.4.46) lib/earmark_parser/ast_renderer.ex:23: Earmark.Parser.AstRenderer._render/3
    (earmark 1.4.46) lib/earmark_parser.ex:592: Earmark.Parser.as_ast/2
    (earmark 1.4.46) lib/earmark.ex:234: Earmark.as_ast/2
amit-chaudhari1 commented 2 months ago

Hello! I've been swamped with my actual job, sorry for the delay, I'll take a look into this,

Could you share the file or parts of it that caused this? It would be helpful for reproducing this on my machine.

dominicletz commented 2 months ago

Should be easy to reproduce with this: Earmark.as_ast("\\[{:}")

RobertDober commented 2 months ago

@amit-chaudhari1 I missed the bug report in the discussion, shall I close #501 , which is a duplicate, or would you prefer to close thi?

amit-chaudhari1 commented 2 months ago

I'll close this as duplicate.

RobertDober commented 2 months ago

ok I am on it then ...