noties / Prism4j

Simplified Java clone of prism-js
Apache License 2.0
50 stars 14 forks source link

Empty string input crashes #8

Open noties opened 4 years ago

noties commented 4 years ago

https://github.com/noties/Markwon/issues/192

Meisolsson commented 4 years ago

I'm having this issue with the following markdown file https://raw.githubusercontent.com/yahoo/gifshot/master/README.md

Is there any idea on how to solve this in Prism4j?

noties commented 4 years ago

Hello @Meisolsson !

At first I thought those 2 issues are unreleated. As markdown file that you'd linked does not contain empty code blocks. Then I have found out that the block that fails is:

<script src='gifshot.js'></script>

which does not make sense as it is not empty. If you change script to any other tag, then no crash happens 🤔 . It turns out that javascript grammar injects itself into html grammar to handle this specific case -> javascript code inside <script> tags. But then it is invoked with empty string (as tag does not contain any text)

Meisolsson commented 4 years ago

Alright, any idea how to solve it? I'm guessing that the check causing the crash is required for something else.

noties commented 4 years ago

The fix must be implemented in the library - Prism4j must not tokenize empty inputs

alexrintt commented 1 year ago

The fix must be implemented in the library - Prism4j must not tokenize empty inputs

Is this fix published or we need to do some dependency workaround to include a fork?

Mine version is 2.0.0, which seems to be the latest, and it's failing for this markdown file:

https://github.com/adambard/learnxinyminutes-docs/blob/master/amd.html.markdown

(disregard the frontmatter since it's not being passed to the markown -> prism4j library).