pydantic / pydantic/httpx2

Constrain which encodings are supported by `response.text`.

Open Beginner friendly
#788 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
78
Avg merge
8h 59m
Merged PRs (30d)
24

Description

Originally opened by @tomchristie on 2023-10-13 12:44:05 in encode/httpx

  • Initially raised as discussion #2881

Currently when accessing response.text any installed codec may be loaded, depending on the Content-Type header of the response. This is problematic partly because not all codecs are text codecs. It also feels too open, as custom codecs might be installed with arbitrary behaviours.

May suggestion would be that we support the same set of encodings as the chromium browser... https://chromium.googlesource.com/chromium/chromium/+/refs/heads/trunk/chrome/browser/character_encoding.cc#36

We can effect this change by having a hardcoded set of supported codecs, here...

https://github.com/encode/httpx/blob/e63b6594f2863b7c8274eb0991ebc6cad63661f7/httpx/_utils.py#L71-L79

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in httpx/_utils.py at the hardcoded codec set referenced by the issue, then compare it with Chromium’s supported encoding list. Trace how response.text resolves the Content-Type encoding and inspect the existing tests covering response text or codecs. Done means response.text is limited to the supported set and does not load arbitrary installed codecs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Feature
Difficulty
2/5
Estimated time
Half a day
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.