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

Incorrectly detects an ordered list when there isn't one #95

Closed
ec1oud opened this issue Oct 4, 2019 · 8 comments
Closed

Incorrectly detects an ordered list when there isn't one #95

ec1oud opened this issue Oct 4, 2019 · 8 comments
Labels

Comments

@ec1oud
Copy link
Contributor

ec1oud commented Oct 4, 2019

If the input is simply ".\n" (an actual newline there), the leave-block callback is invoked with MD_BLOCK_OL. Found by fuzzing: https://bugreports.qt.io/browse/QTBUG-78870

@mity mity added the bug label Oct 4, 2019
@mity mity closed this as completed in 0354e1a Oct 4, 2019
@mity
Copy link
Owner

mity commented Oct 4, 2019

Fixed. Thanks for reporting it.

@mity
Copy link
Owner

mity commented Oct 4, 2019

@ec1oud To prevent a misunderstanding, I fixed generating bad output as in:

$ printf '.\n' | ./md2html/md2html
<ol start="0">
<li></li>
</ol>

After the fix applied:

$ printf '.\n' | ./md2html/md2html
<p>.</p>

I am confused by the info in the https://bugreports.qt.io/browse/QTBUG-78870 that only the leave callback is called. Imho that cannot be true because md2html sees the enter event too as it outputs the opening tag. Can you please double check that?

@ec1oud
Copy link
Contributor Author

ec1oud commented Oct 4, 2019

Yes you're right, the enter callback is called with MD_BLOCK_OL. I just didn't push anything on my stack because there were no list items, so it's probably really a good idea to check whether it's empty before popping.

@mity
Copy link
Owner

mity commented Oct 4, 2019

But that is imho not a correct fix. Consider the empty list is nested in a parent list. The stack isn't then empty, yet you will happily pop it and end the parent list too early.

@ec1oud
Copy link
Contributor Author

ec1oud commented Oct 4, 2019

Should empty lists still happen in some cases?

@mity
Copy link
Owner

mity commented Oct 4, 2019

Yes. The list item mark not followed by text but just a new-line forms an empty list item with no text.

$ printf '*\n' | /src/cmark/build/src/cmark
<ul>
<li></li>
</ul>

And these can be nested in each other. E.g.

$ printf '*\n  *\n  *\n' | /src/cmark/build/src/cmark
<ul>
<li>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>

@ec1oud
Copy link
Contributor Author

ec1oud commented Oct 4, 2019

OK. Will have to take care of that then. Thanks for your help; I'll get back to it in a day or two.

@mity
Copy link
Owner

mity commented Oct 4, 2019

Why you cannot push to the list stack directly from the cbEnterBlock() instead postponing it via the flag machinery? It would imho fix your issue and also simplify the code.

@mity mity changed the title incorrectly detects end of a list when there wasn't one Incorrectly detects an ordered list when there isn't one Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants