You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Describe the bug
🐞 Bug Report
Describe the bug
When using shiki's JavaScript regex engine to parse Go code containing struct definitions with comments, the parser experiences catastrophic backtracking and becomes unresponsive (hangs indefinitely). This issue specifically occurs with Go struct definitions that have inline comments using //.
The issue is located in the Go language definition file (packages/langs/dist/go.mjs) within the struct_variables_types_fields patterns. Specifically, the regex pattern contains \\S+ which greedily matches all non-whitespace characters, including comment symbols //.
When encountering struct definitions with comments, the \\S+ pattern attempts to match the comment symbols, causing massive backtracking operations and resulting in catastrophic backtracking.
The Go syntax highlighter should process struct definitions with comments quickly (within milliseconds) without hanging.
Actual Behavior
The parser hangs indefinitely (>10 seconds) when encountering Go struct definitions with inline comments.
Additional Information
I have already implemented and tested a fix for this issue. The fix involves modifying 2 regex patterns in the Go language definition file, replacing \\S+ with [^\\s/]+. After applying the fix:
Original problematic code: 59.00ms (vs. hanging before)
Validations
Describe the bug
🐞 Bug Report
Describe the bug
When using shiki's JavaScript regex engine to parse Go code containing struct definitions with comments, the parser experiences catastrophic backtracking and becomes unresponsive (hangs indefinitely). This issue specifically occurs with Go struct definitions that have inline comments using
//
.Example code that triggers the bug:
The parser hangs when processing this code and never completes the syntax highlighting operation.
Reproduction
Minimal reproduction case:
Environment:
@shikijs/engine-javascript
)Additional test cases that also hang:
Root Cause Analysis
The issue is located in the Go language definition file (
packages/langs/dist/go.mjs
) within thestruct_variables_types_fields
patterns. Specifically, the regex pattern contains\\S+
which greedily matches all non-whitespace characters, including comment symbols//
.When encountering struct definitions with comments, the
\\S+
pattern attempts to match the comment symbols, causing massive backtracking operations and resulting in catastrophic backtracking.Problematic patterns:
repository.struct_variables_types_fields.patterns[3]
\\S+
that matches comment symbolsExpected Behavior
The Go syntax highlighter should process struct definitions with comments quickly (within milliseconds) without hanging.
Actual Behavior
The parser hangs indefinitely (>10 seconds) when encountering Go struct definitions with inline comments.
Additional Information
I have already implemented and tested a fix for this issue. The fix involves modifying 2 regex patterns in the Go language definition file, replacing
\\S+
with[^\\s/]+
. After applying the fix:Reproduction
https://textmate-grammars-themes.netlify.app/?theme=vitesse-dark&grammar=go&code=type+GandalfServer+struct+%7B+%2F%2Fnolint%3Abgolint+%2F%2F+abcde
Contributes
The text was updated successfully, but these errors were encountered: