fix lua regex causing runaway backtracking. by thavelick · Pull Request #2882 · pygments/pygments
This was referenced
Apr 5, 2025Comment on lines +61 to +67
| if sys.version_info >= (3, 11): | ||
| # Use a possessive quantifier to prevent greediness from causing runaway backtracking. | ||
| _space = r'(?:\s++)' | ||
| else: | ||
| # Possessive quantifiers are not available in Python < 3.11. Complex Lua is likely to | ||
| # cause any regex that includes _space to take an exponentially long time. | ||
| _space = r'(?:\s+)' |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that makes sense. I fixed it up and it works as far as I can tell. Thanks for helping simplify.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, works here - appreciate the investigation!
Use negative lookahead to avoid runway backtracking in whitespace. Fixes pygments#2839
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters