Repository navigation
gh-107862: Fix infinite loop in email header folding found by a Hypothesis round-trip test #159771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
pganssle
wants to merge
5
commits into
python:main
Choose a base branch
from
pganssle:email-fold-hypothesis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aeb677f
gh-107862: Add stateful, timezones and ip_addresses to the Hypothesis…
pganssle 76f6a3f
gh-107862: Fix infinite loop folding a character too wide for the line
pganssle 53d13e8
gh-107862: Add expected failure for subjects that look like encoded w…
pganssle c3b2240
Merge remote-tracking branch 'upstream/main' into hypothesis-stubs-st…
pganssle 7f30bad
Merge branch 'hypothesis-stubs-stateful' into email-fold-hypothesis
pganssle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| """Stubs for the subset of ``hypothesis.stateful`` used by the test suite. | ||
|
|
||
| The stateful API has no equivalent of ``@example``, so without Hypothesis | ||
| there is nothing to replay: the ``TestCase`` generated for a state machine | ||
| is skipped, and ``run_state_machine_as_test`` raises ``unittest.SkipTest``. | ||
| The decorators and helpers are accepted so that state machine classes can | ||
| be defined at import time. | ||
| """ | ||
| import unittest | ||
|
|
||
| from ._helpers import stub_factory | ||
| from .strategies import StubStrategy | ||
|
|
||
| __all__ = [ | ||
| "Bundle", | ||
| "MultipleResults", | ||
| "RuleBasedStateMachine", | ||
| "consumes", | ||
| "initialize", | ||
| "invariant", | ||
| "multiple", | ||
| "precondition", | ||
| "rule", | ||
| "run_state_machine_as_test", | ||
| ] | ||
|
|
||
| _SKIP_REASON = "Hypothesis required for stateful test" | ||
|
|
||
| Bundle = stub_factory(StubStrategy, "hypothesis.stateful.Bundle") | ||
|
|
||
|
|
||
| def consumes(bundle): | ||
| return bundle | ||
|
|
||
|
|
||
| class MultipleResults: | ||
| def __init__(self, *values): | ||
| self.values = values | ||
|
|
||
|
|
||
| def multiple(*args): | ||
| return MultipleResults(*args) | ||
|
|
||
|
|
||
| def _identity_operator(f): | ||
| return f | ||
|
|
||
|
|
||
| def _identity_decorator(*_args, **_kwargs): | ||
| return _identity_operator | ||
|
|
||
|
|
||
| rule = _identity_decorator | ||
| initialize = _identity_decorator | ||
| invariant = _identity_decorator | ||
| precondition = _identity_decorator | ||
|
|
||
|
|
||
| class _TestCaseProperty: | ||
| """Build (and cache) a skipped ``unittest.TestCase`` per state machine.""" | ||
|
|
||
| def __init__(self): | ||
| self._cases = {} | ||
|
|
||
| def __get__(self, obj, owner): | ||
| if owner not in self._cases: | ||
|
|
||
| class StateMachineTestCase(unittest.TestCase): | ||
| settings = None | ||
|
|
||
| def runTest(self): | ||
| raise unittest.SkipTest(_SKIP_REASON) | ||
|
|
||
| StateMachineTestCase.__name__ = f"{owner.__name__}.TestCase" | ||
| StateMachineTestCase.__qualname__ = f"{owner.__qualname__}.TestCase" | ||
| self._cases[owner] = StateMachineTestCase | ||
| return self._cases[owner] | ||
|
|
||
|
|
||
| class RuleBasedStateMachine: | ||
| TestCase = _TestCaseProperty() | ||
|
|
||
| def bundle(self, name): | ||
| return Bundle(name) | ||
|
|
||
| def check_invariants(self, settings, output, runtimes): | ||
| pass | ||
|
|
||
| def setup_state(self): | ||
| pass | ||
|
|
||
| def teardown(self): | ||
| pass | ||
|
|
||
|
|
||
| def run_state_machine_as_test(state_machine_factory, *, settings=None): | ||
| raise unittest.SkipTest(_SKIP_REASON) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2026-10-19-17-06-00.gh-issue-107862.mB7kWe.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix an infinite loop in :mod:`email` header folding when a single character's | ||
| :rfc:`2047` encoded word is wider than the policy's ``max_line_length``; the | ||
| line now exceeds the limit instead. |
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Tests/2026-10-19-17-05-00.gh-issue-107862.qH3sTa.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add ``hypothesis.stateful`` and the ``timezones()`` and ``ip_addresses()`` | ||
| strategies to the Hypothesis stubs used when Hypothesis is not installed. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.