shikijs / textmate-grammars-themes

Collection of TextMate grammars and themes in JSON
https://textmate-grammars-themes.netlify.app/
MIT License
116 stars 57 forks source link

MDC grammar contains invalid Oniguruma token `[^]` #105

Closed slevithan closed 1 day ago

slevithan commented 4 days ago

This line in the MDC grammar is an invalid Oniguruma pattern. The behavior for TextMate grammars when an invalid pattern is encountered (dutifully reproduced by vscode-textmate) is to silently fail, causing the regex to never match. So whatever it's intended to do is not happening.

The error in this pattern is the use of [^]]. From context, it's easy to figure out that the author meant for this to mean "match any character except ]"). However, that's not what it's doing. There are several different ways that different regex engines interpret this:

To fix this, the [^]] should be replaced with [^\\]] (escaped backslash since it's in a JS string). It will then run in Oniguruma.

antfu commented 2 days ago

Hey @slevithan, thanks a lot for sorting them out! It must a lot of work, and it would benefit the ecosystem a lot!

However, this repo does not control those grammars; it only syncs and normalizes them. Here is the list of each grammar's source repo, would you be interested in cross-post in the corresponding repos as well, so the original authors/maintainers should be aware of them and fix. If their maintenance is stale and then we could consider how we patch them here as workarounds.

slevithan commented 1 day ago

However, this repo does not control those grammars; it only syncs and normalizes them. Here is the list of each grammar's source repo

Found the list here. No problem, and thanks for the details. Reported this upstream here, and also reported the other recent issues I filed here upstream.

thanks a lot for sorting them out! It must a lot of work, and it would benefit the ecosystem a lot!

Thanks, but this actually doesn’t take much effort 😊 since I’m reporting rules I’ve already coded into oniguruma-to-es. Understanding the innumerable cross-flavor regex differences out there has long been an interest for me, and is something I’ve extensively researched in the past e.g. for Regular Expressions Cookbook, and of course when recently developing Oniguruma-To-ES.