diff --git a/lib/lexer_mdx.mll b/lib/lexer_mdx.mll index 683abc81..960d087f 100644 --- a/lib/lexer_mdx.mll +++ b/lib/lexer_mdx.mll @@ -56,7 +56,8 @@ rule text section = parse `Text str :: text section lexbuf } and block = parse - | eof | ws* as end_pad "```" ws* eol + | eof { [""] } + | ws* as end_pad "```" ws* eol { newline lexbuf; [end_pad] } | ([^'\n']* as str) eol diff --git a/test/bin/mdx-test/expect/dune.inc b/test/bin/mdx-test/expect/dune.inc index f489a3e2..82bdf588 100644 --- a/test/bin/mdx-test/expect/dune.inc +++ b/test/bin/mdx-test/expect/dune.inc @@ -575,6 +575,18 @@ (alias runtest) (action (diff trailing-whitespaces/test-case.md.expected trailing-whitespaces.actual))) +(rule + (target unclosed-block.actual) + (deps (package mdx) (source_tree unclosed-block)) + (action + (with-stdout-to %{target} + (chdir unclosed-block + (run ocaml-mdx test --output - test-case.md))))) + +(rule + (alias runtest) + (action (diff unclosed-block/test-case.md.expected unclosed-block.actual))) + (rule (target warnings.actual) (deps (package mdx) (source_tree warnings)) diff --git a/test/bin/mdx-test/expect/unclosed-block/test-case.md b/test/bin/mdx-test/expect/unclosed-block/test-case.md new file mode 100644 index 00000000..3b1b42a1 --- /dev/null +++ b/test/bin/mdx-test/expect/unclosed-block/test-case.md @@ -0,0 +1,7 @@ +Here is a good block: + +```ocaml +``` + +And here is one that is not closed, this should not cause an infinite loop in the lexer: +``` diff --git a/test/bin/mdx-test/expect/unclosed-block/test-case.md.expected b/test/bin/mdx-test/expect/unclosed-block/test-case.md.expected new file mode 100644 index 00000000..14a4ff19 --- /dev/null +++ b/test/bin/mdx-test/expect/unclosed-block/test-case.md.expected @@ -0,0 +1,8 @@ +Here is a good block: + +```ocaml +``` + +And here is one that is not closed, this should not cause an infinite loop in the lexer: +``` +```