codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.94k stars 376 forks source link

Sass indented syntax infinite loop when deleting a `}` #1442

Closed jamesnw closed 2 months ago

jamesnw commented 2 months ago

Describe the issue

In some situations when using the Indented Syntax in Sass, deleting a } will cause an infinite loop.

To replicate:

  1. Open the Reproduction Link
  2. After the a, type {.
  3. CodeMirror will match the brace and add a }
  4. Arrow right, and type Delete to try to remove the }.

I can consistently make the browser crash with these steps.

Browser and platform

Chromium 128.0.6613.138

Reproduction link

https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQge3Nhc3N9IGZyb20gIkBjb2RlbWlycm9yL2xhbmctc2FzcyIKCm5ldyBFZGl0b3JWaWV3KHsKICBkb2M6ICJhXG4gIGNvbG9yOiByZWQiLAogIGV4dGVuc2lvbnM6IFtiYXNpY1NldHVwLCBzYXNzKHtpbmRlbnRlZDogdHJ1ZX0pXSwKICBwYXJlbnQ6IGRvY3VtZW50LmJvZHkKfSkK

marijnh commented 2 months ago

A careless use of a rule that could match a zero-length end-of-file token made the grammar loop. Attached patch fixes it.

jamesnw commented 2 months ago

Thanks for the quick fix!