get_encoding_from_headers treats any content type containing 'text' as text/* (ISO-8859-1)
@suyashgitt がすでに取り組んでいます。
2026年11月13日 から。
評価
調査の方向性
src/requests/utils.pyを読み、get_encoding_from_headersを調べてから、この関数を対象とするテストを探してください。application/vnd.context+xml、application/x-context、application/jsonxのメディアタイプで報告された動作を再現してください。実際のtext/*タイプだけがISO-8859-1を受け取り、一致しないタイプはNoneを返し、各ケースがテストでカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
requests.utils.get_encoding_from_headers uses substring checks on the media type, so non-text/* types that merely contain the letters "text" are treated as text and get ISO-8859-1.
In src/requests/utils.py:
if "text" in content_type:
return "ISO-8859-1"
Repro
from requests.utils import get_encoding_from_headers
from requests.structures import CaseInsensitiveDict as C
get_encoding_from_headers(C({"content-type": "application/vnd.context+xml"})) # 'ISO-8859-1'
get_encoding_from_headers(C({"content-type": "application/x-context"})) # 'ISO-8859-1'
Neither is a text/* type, so Response.encoding should be None (letting content-based detection run), not Latin-1. The same substring pattern is used for "application/json" in content_type, which would also match e.g. application/jsonx.
Suggested fix
Compare against the parsed media type, e.g. content_type.startswith("text/") and content_type == "application/json". Happy to open a PR with tests.
Checked on current main; I found no existing issue covering this.
- 主要言語
- Python
- スター
- 54.7k
- フォーク
- 10.8k
- 平均マージ
- 18分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
psf/requests のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
`iter_lines(decode_unicode=True, delimiter=<str>)` raises `TypeError` when `Response.encoding` is `None`再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Invalid `params` type (e.g. int) raises misleading "TypeError: Cannot mix str and non-str arguments"オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
OCA/account-invoicing#2529 ·
メンテナーはふだん 1 日以内に返信
-
area/ci
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
ImageGen generate-batch aborts valid JSONL jobs containing a Unicode line separator in poster textオープンbug imagen skills
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Email validation accepts a trailing newline対応中かも @marcello-pichini が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信