Markup.striptags collects text into a list in a single pass to fix a performance regression caused by quadratic string manipulation F-32. This approach ensures the function scales linearly with input size, whereas previous incremental removal methods were significantly slower on large inputs F-35 F-32.
What changed
The implementation was updated to use a single while loop that scans for tags using str.find, appends the text between tags to a list named parts, and joins them once at the end F-07 F-32. This replaced a "naive" refactor that had attempted to remove regular expressions by incrementally removing blocks, which resulted in quadratic complexity F-31 F-32.
Why
The change was motivated by benchmarks showing that the previous incremental approach was up to 1000x slower than the original regex-based version for large inputs F-35. While the maintainers wanted to avoid regex due to its own performance issues and deep call stacks, the initial replacement was inefficient because it performed repeated string manipulations F-32 F-35. The single-pass list-collection method matches the style used for other scanners in Werkzeug to provide better performance without using regex F-32.
High confidence
4 sources cited · 2 hops · 8 LLM calls · 26,611 tokens · 44s