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

Add try catch to unguarded JSON.parse #3850

Open
jcubic opened this issue Dec 22, 2024 · 0 comments
Open

Add try catch to unguarded JSON.parse #3850

jcubic opened this issue Dec 22, 2024 · 0 comments

Comments

@jcubic
Copy link
Contributor

jcubic commented Dec 22, 2024

Information:

  • Prism version: [e.g. 1.14, latest from the download page, etc.]: latest
  • Plugins: [a list of plugins you are using or 'none']: none
  • Environment: [e.g. Browser, Node, Webpack]: browser

Description
Inside the code, there is this snippet:

if (!_.disableWorkerMessageHandler) {
	// In worker
	_self.addEventListener('message', function (evt) {
		var message = JSON.parse(evt.data);
		var lang = message.language;
		var code = message.code;
		var immediateClose = message.immediateClose;
        
		_self.postMessage(_.highlight(code, _.languages[lang], lang));
		if (immediateClose) {
			_self.close();
		}
	}, false);
}

And it interferes with other code that don't send JSON data. We can add try catch that is ignored?
Probably my Chrome extensions.

Adding this:

window.Prism = window.Prism || {};
Prism.disableWorkerMessageHandler = true;

Makes no difference, I keep getting JSON parse error in console when including Prism.js.

I can create a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant