wbaldoumas / markdown-colorcode

An extension for Markdig that adds syntax highlighting to code through the power of ColorCode-Universal.
https://wbaldoumas.github.io/markdown-colorcode/
MIT License
29 stars 5 forks source link

Some json makes the coloration seems to be stuck in an infinite loop #169

Closed hoverwars closed 1 month ago

hoverwars commented 1 month ago

Description

I'm developping an AI chat that can generate code. I use your package to colorate the code. Sometimes, the coloration seems to be stuck in an infinite loop, making my application freeze. What I know:

Expected Behaviour

The generation working, even for incomplete code blocks

Actual Behaviour

The coloration seems to be stuck in an infinite loop.

Affected Version

2.3.0

Steps to Reproduce

Examples

Here are some examples that cause the program to be stuck. Note that the not closing tag "```json" is on purpose, because the problem occurs during the AI answer, so the generation cannot end.

```json
{
    "NomDuSnippet": {
        "prefix": "monSnippet",
        "body": [
            "Nom : ${1:MonNom}",
            "Date : ${2:LaDate}",
            "Description : ${3:MaDescription

Another one (doesn't stuck but take ~1 second to colorate):

```json
{
  "My JSON Template": {
    "prefix": "mytemplate",
    "body": [
      "{",
      "  \"username\": \"${1:default

I have these that might help you. Crash

```json
[
    {
        "NOM DU CANDIDAT": "GROUPE BIDULE",
        "DESCRIPTION": "Vérification des systemes de

Don't crash

```json
[
    {
        "NOM DU CANDIDAT": "GROUPE BIDULE",
        "DESCRIPTION": "Vérification

Don't crash

```json
[
    {
        "NOM DU CANDIDAT": "GROUPE BIDULE",
        "DESCRIPTION": "Vérification des systemes de"

In my opinion, it might be related to the usage of spaces in a non-closing double quote Let me know if you need more informations

Checklist

hoverwars commented 1 month ago

EDIT: It occured on a mermaid block too

wbaldoumas commented 1 month ago

@hoverwars thanks for reporting this issue!

Could you share a minimal reproduction project (either a public github repo or a zip upload of the code here)? I'll take a look when I have time.

wbaldoumas commented 1 month ago

@hoverwars I found https://github.com/CommunityToolkit/ColorCode-Universal/issues/36 which appears to basically be the same issue that you reported here. The root cause exists over in that library, which this extension uses as a dependency.

Please report your issue there to add some urgency. It also looks like some workarounds were posted which may be helpful for you. Closing this issue out, as there isn't anything to address in this package.

hoverwars commented 1 month ago

Thank you for your help. I'm sorry, I didn't take the time this week to create the repository you asked. Have a good day !

wbaldoumas commented 1 month ago

Thank you for your help. I'm sorry, I didn't take the time this week to create the repository you asked. Have a good day !

Not a problem! I was able to use some of the examples you provided to build a small repro app to test locally. That let me drill down to observe ColorCode-Universal as being the root cause and then I found that related issue.

If you find any other issues with this library, feel free to open another issue and I'll be happy to help!