Skip to content

fix(bash) match a function header only at a word boundary - #4552

Open
MaciejZet wants to merge 1 commit into
highlightjs:mainfrom
MaciejZet:fix/bash-function-backtracking
Open

MaciejZet wants to merge 1 commit into
highlightjs:mainfrom
MaciejZet:fix/bash-function-backtracking

Conversation

@MaciejZet

Copy link
Copy Markdown

Refs #4529

Changes

The Bash function rule could start in the middle of a word. On a long word it retried the name from every character while looking for () {, so the cost grew with the square of the input. A 64 KB word took about 2.3 s; with the word-boundary anchor the same input finishes in under a millisecond.

foo() {, my_func () {, and a header after another command still highlight the function name. This is one grammar from #4529, so the issue stays open.

Checklist

  • Added markup tests, or they don't apply here because...
  • I have read and followed our AI-assisted contributions policy (human review, no slop)

A long word was rescanned from every character while the grammar looked for `() {`.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant