Skip to content

Commit

Permalink
Merge pull request #444 from edwintorok/no-inf
Browse files Browse the repository at this point in the history
Avoid infinite loop in lexer on unclosed code block
  • Loading branch information
samoht authored Dec 6, 2024
2 parents e2b6532 + 9a8facd commit 10b8e69
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/lexer_mdx.mll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/bin/mdx-test/expect/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions test/bin/mdx-test/expect/unclosed-block/test-case.md
Original file line number Diff line number Diff line change
@@ -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:
```
8 changes: 8 additions & 0 deletions test/bin/mdx-test/expect/unclosed-block/test-case.md.expected
Original file line number Diff line number Diff line change
@@ -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:
```
```

0 comments on commit 10b8e69

Please sign in to comment.