1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-25 21:39:02 +02:00

Add a timeout to regexes.

This avoids pathologically bad match times. Fixes #378.
This commit is contained in:
Alec Thomas 2020-07-08 20:22:02 +10:00
parent 5756434ec2
commit e62d93f4aa

View File

@ -6,6 +6,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"sync" "sync"
"time"
"unicode/utf8" "unicode/utf8"
"github.com/dlclark/regexp2" "github.com/dlclark/regexp2"
@ -393,6 +394,7 @@ func (r *RegexLexer) maybeCompile() (err error) {
if err != nil { if err != nil {
return fmt.Errorf("failed to compile rule %s.%d: %s", state, i, err) return fmt.Errorf("failed to compile rule %s.%d: %s", state, i, err)
} }
rule.Regexp.MatchTimeout = time.Millisecond * 250
} }
} }
} }