Subject: bug#53203: Comment with lots of color codes crashes or hangs emacs in scss-mode

From: Lars Ingebrigtsen <[email-masked]>
Date: Thu, 13 Jan 2022 08:00:18 +0100

Eli Zaretskii <[email-masked]> writes:

> It seems to infloop in JIT font-lock, and the culprit seems to be this
> part of font-lock-keywords:
>
>        ;; Even though pseudo-elements should be prefixed by ::, a
>        ;; single colon is accepted for backward compatibility.
>        "\\(?:\\(:" (regexp-opt (append css-pseudo-class-ids
>                                        css-pseudo-element-ids)
>                                t)

Trying to understand the regexp used for scss here, I think that bit is
somewhat innocuous -- it just matches those words.

       ;; Even though pseudo-elements should be prefixed by ::, a
       ;; single colon is accepted for backward compatibility.
       "\\(?:\\(:" (regexp-opt (append css-pseudo-class-ids
                                       css-pseudo-element-ids)
                               t)
       "\\|::" (regexp-opt css-pseudo-element-ids t) "\\)"

But then we get:

       "\\(?:([^)]+)\\)?"
       (if (not sassy)
           "[^:{}()\n]*"
         (concat "[^:{}()\n#]*\\(?:" scss--hash-re "[^:{}()\n#]*\\)*"))
       "\\)*"

Which is a whole lot of backtracking, presumably exacerbated by the
previous ids bit of the regexp.

But I've repressed all I once knew about the scss language -- what is it
really trying to match here?  Anybody?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no