Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spacy/lang/tokenizer_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# (see: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml)
r"(?:(?:[\w\+\-\.]{2,})://)?"
# mailto:user or user:pass authentication
r"(?:\S+(?::\S*)?@)?"
r"(?:\S+@)?"
r"(?:"
# IP address exclusion
# private & local networks
Expand Down
20 changes: 19 additions & 1 deletion spacy/tests/tokenizer/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import time

import pytest

from spacy.lang.tokenizer_exceptions import BASE_EXCEPTIONS
from spacy.lang.tokenizer_exceptions import BASE_EXCEPTIONS, URL_MATCH

URLS_BASIC = [
"http://www.nytimes.com/2016/04/20/us/politics/new-york-primary-preview.html?hp&action=click&pgtype=Homepage&clickSource=story-heading&module=a-lede-package-region&region=top-news&WT.nav=top-news&_r=0",
Expand Down Expand Up @@ -203,3 +205,19 @@ def test_tokenizer_handles_two_suffix_url(tokenizer, suffix1, suffix2, url):
assert tokens[0].text == url
assert tokens[1].text == suffix1
assert tokens[2].text == suffix2


@pytest.mark.parametrize(
"pathological_url",
[
"a:" * 20000 + "!",
("aa://" * 20000) + "!",
],
ids=["colon-runs", "scheme-runs"],
)
def test_url_match_auth_group_is_linear(pathological_url):
# regression test to prevent O(n**2) regex matches
start = time.perf_counter()
assert URL_MATCH(pathological_url) is None
elapsed = time.perf_counter() - start
assert elapsed < 0.3