Skip to content

Fix regex of URL quadratic backtracking - #14016

Open
Fazel94 wants to merge 1 commit into
explosion:masterfrom
Fazel94:master
Open

Fix regex of URL quadratic backtracking#14016
Fazel94 wants to merge 1 commit into
explosion:masterfrom
Fazel94:master

Conversation

@Fazel94

@Fazel94 Fazel94 commented Aug 17, 2026

Copy link
Copy Markdown

URL regex quardratic backtracking

Description

In spacy/lang/tokenizer_exceptions.py:16 the regex for mailto:user or user:pass auth faces takes quardratic time to match crafted examples like "a:"*16000.

Code to reproduce the issue:

import time
import spacy

nlp = spacy.blank("en")

for n in (1000, 2000, 4000, 8000, 16000):
    text = "a:" * n
    start = time.perf_counter()
    nlp(text)
    print(f"{len(text):>6} chars  {time.perf_counter() - start:7.2f}s")

On the current master would write:

  2000 chars     0.03s
  4000 chars     0.08s
  8000 chars     0.36s
 16000 chars     1.20s
 32000 chars     4.76s

On the PR it would produce:

  2000 chars     0.01s
  4000 chars     0.01s
  8000 chars     0.03s
 16000 chars     0.05s
 32000 chars     0.10s

For tests I have added two pathological cases and measure their time to prevent regression.

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

@Fazel94 Fazel94 changed the title Fix regex of URL auth group quantifier quadratic backtracking Fix regex of URL quadratic backtracking Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant