imaplib.Time2Internaldate raises IndexError instead of ValueError on an empty string
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
imaplib.Time2Internaldate is documented to raise ValueError for input that is not of a known type, and its own final branch is raise ValueError("date_time not of a known type"). However, the string branch subscripts the value before that check:
elif isinstance(date_time, str) and (date_time[0],date_time[-1]) == ('"','"'):
so an empty string escapes as a bare IndexError instead:
>>> import imaplib
>>> imaplib.Time2Internaldate('')
Traceback (most recent call last):
...
IndexError: string index out of range
>>> imaplib.Time2Internaldate('x') # non-empty unquoted string is fine
Traceback (most recent call last):
...
ValueError: date_time not of a known type
The fix is to use slices so the comparison is simply false for an empty string and control falls through to the intended ValueError:
elif isinstance(date_time, str) and (date_time[:1], date_time[-1:]) == ('"', '"'):
Behavior for all other inputs is unchanged. Related: gh-86165 recently fixed a different crash in this same function. I have a PR ready with the fix, a regression test, and a NEWS entry.
CPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-153874
- gh-153929
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
エントリポイント imaplib.Time2Internaldate から開始し、issue で報告されている空文字列のパスを確認します。issue で言及されている回帰テストと NEWS エントリを確認します。空の入力で ValueError が発生し、その他の入力では動作が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- networking
- issue の種類
- バグ
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 20/100