Catastrophic backtracking in Typogrify::dash()

Created on 20 October 2024, about 1 month ago

Problem/Motivation

When calling Typogrify::dash() on a long repeated string, it can cause catastrophic backtracking. The steps to find matches increase exponentially and it can cause bad performances or even make preg_replace() fail entirely.

Steps to reproduce

Call Typogrify::dash() on the string in the attached file.
preg_replace() fails and returns null.

Proposed resolution

I am not sure what the correct solution is.
This article may help: https://www.regular-expressions.info/catastrophic.html

🐛 Bug report
Status

Active

Version

1.3

Component

Code

Created by

🇫🇷France prudloff Lille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024