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

Gracefully handle invalid bibtex #3

Closed
chfritz opened this issue Jun 11, 2023 · 4 comments
Closed

Gracefully handle invalid bibtex #3

chfritz opened this issue Jun 11, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@chfritz
Copy link

chfritz commented Jun 11, 2023

First off, thanks a lot for this great prism extension! I've been using it in an online bibtex editor context and it's been working great for the most part, however I've noticed that it sometimes hangs itself when trying to parse invalid bibtex, which of course happens a lot during editing.

I've been able to reliably reproduce this by starting a bibtex file with:

@article{newpaper,
  title=

@article{existing,
  title={my old title}
}

Somehow, at this particular moment in editing, the plugin appears to go into an infinite loop, because the tab's CPU goes to 100% and freezes completely.

Any idea whether this can be fixed? Simply punting and giving up would be fine in my context (i.e., only highlight when valid).

@SaswatPadhi
Copy link
Owner

Hi @chfritz,

Thanks for the report and the minimal example.

I tried to reproduce locally, but unfortunately I cannot. I tried two approaches:

  • placing your example within a Markdown: bib code block
  • placing your example within HTML: <pre><code class='language-bib'> ... </code></pre>

In both cases, the rendering seemed to terminate and the output looks okay to me:

Screenshot 2023-06-11 at 21-20-19 JSFiddle - Code Playground

Here is a link to the JSFiddle playground: https://jsfiddle.net/tgk8v29u/

I tried the above with PrismJS versions 1.23.0 (last tested version for this plugin) and 1.29.0 (current latest version).

Please let me know more about your environment. If you could provide a link to your page where this issue occurs, that would also be super helpful.

@chfritz
Copy link
Author

chfritz commented Jun 11, 2023

Ah, correction, the error happens when typing the next character. I'm able to reproduce it in the jsfiddle you provided -- very helpful, thanks! -- when using this:

@article{newpaper,
  title={

@article{existing,
  title={my old title}
}

SaswatPadhi added a commit that referenced this issue Jun 12, 2023
simplified quoted-strings pattern,
fixed 4-level nested brace matching (see: #3),
fixed `=` sign in front of field values being included in value `string`
@SaswatPadhi
Copy link
Owner

Thanks again @chfritz! I was able to reproduce the bug and was able to fix it. While at it, I pushed a few other simplifications & minor fixes as well.

Please see the working example at https://saswat.padhi.me/prismjs-bibtex/broken.html -- shouldn't hang your browser :)

Closing this issue, but please feel free to reopen if this hasn't been adequately resolved.

Thanks and regards.
Saswat

@SaswatPadhi SaswatPadhi added the bug Something isn't working label Jun 12, 2023
@chfritz
Copy link
Author

chfritz commented Jun 12, 2023

Confirmed. Thanks so much for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants