Opened 5 years ago

Closed 5 years 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: dev
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 by Jon Dufresne, 5 years ago

Has patch: set

comment:2 by Mariusz Felisiak, 5 years ago

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 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

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