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
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bug report!
* `François Boulogne <http://www.sciunto.org/>`_
* `Adrian Damian <https://death.andgravity.com/>`_
* `Jason Diamond <http://injektilo.org/>`_
* `Vincent Gao <https://github.com/gaoflow>`_
* `Jakub Kuczys <https://github.com/jack1142>`_
* `Fazal Majid <https://majid.info/blog/>`_
* `Kevin Marks <http://epeus.blogspot.com/>`_
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/_6-gaoflow-author-email-redos.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fixed
-----

* Avoid repeated rescans when extracting emails from malformed author values. (#562)
1 change: 1 addition & 0 deletions feedparser/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .util import FeedParserDict

email_pattern = re.compile(
r"(?<![a-zA-Z0-9_.+-])"
r"(([a-zA-Z0-9_.+-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)"
r"|(([a-zA-Z0-9-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?))"
r"(\?subject=\S+)?"
Expand Down
16 changes: 16 additions & 0 deletions tests/test_author_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Exercise author email extraction."""

import time

from feedparser.mixin import email_pattern


def test_email_pattern_rejects_pathological_domain_quickly():
"""Reject an email-like author without repeatedly rescanning its domain."""
author = "user@" + ("a-b." * 5000) + "!"

start = time.perf_counter()
assert email_pattern.search(author) is None
elapsed = time.perf_counter() - start

assert elapsed < 0.1