Opened 5 months ago

Closed 5 months ago

#30550 closed Bug (fixed)

TestClient's response.json() should decode content using the response charset.

Reported by: Jon Dufresne Owned by: Jon Dufresne
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Right now, response.json() always decodes using utf-8.

https://github.com/django/django/blob/8ba20d9071e9e1b8f2c81d4df977db4278342085/django/test/client.py#L646-L654

response._json = json.loads(response.content.decode(), **extra)

While this is frequently correct, the response may be any encoding. If it is a non-UTF-8 encoding, the content should be decoded as such.

Change History (3)

comment:1 Changed 5 months ago by Jon Dufresne

Has patch: set

comment:2 Changed 5 months ago by felixxm

Owner: changed from nobody to Jon Dufresne
Status: newassigned
Summary: TestClient's response.json() should decode content using the response charsetTestClient's response.json() should decode content using the response charset.
Triage Stage: UnreviewedAccepted

comment:3 Changed 5 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In d6ea4898:

Fixed #30550 -- Fixed decoding of non-UTF-8 bytes objects in response.json().

Note: See TracTickets for help on using tickets.
Back to Top