Skip to content

Commit

Permalink
pygments2chroma: escape regex.words (#982)
Browse files Browse the repository at this point in the history
Discovered while building on top of
#877 (comment)
(by @miliog)

The pygments "regex.words" should be escaped, since they may contain
special regex chars (like `^` or `+`).
  • Loading branch information
oliverpool authored Jul 10, 2024
1 parent 7677251 commit e06b528
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion _tools/pygments2chroma_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def translate_rules(rules):
regex = xml_regex(regex)
elif isinstance(regex, pygments_lexer.words):
regex = xml_string('%s(%s)%s' % (regex.prefix,
'|'.join(w for w in regex.words),
'|'.join(re.escape(w) for w in regex.words),
regex.suffix))
else:
raise ValueError('expected regex string but got %r' % regex)
Expand Down

0 comments on commit e06b528

Please sign in to comment.