Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid infinite loop in lexer on unclosed code block #444

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
```
```
Loading