Opened 22 months ago

Closed 22 months ago

Last modified 22 months ago

#29662 closed Cleanup/optimization (fixed)

Test client should accept json types with structured suffixes

Reported by: Marnanel Thurman Owned by: Zach Bresser
Component: Testing framework Version: 2.1
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 (last modified by Ramiro Morales)

The test client's json() method should permit the Content-Type of the response to contain structured suffixes, such as "application/activity+json".

This requires a regexp such as "^application\/(.+\+)?json".

See RFC 6838 for the specification: https://tools.ietf.org/html/rfc6838#section-4.2.8
An example in the official registry: https://www.iana.org/assignments/media-types/application/activity+json

Issue #27622 provided a partial fix but allowed only vendor-specific prefixes.

Change History (9)

comment:1 Changed 22 months ago by Claude Paroz

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

comment:2 Changed 22 months ago by Ramiro Morales

Description: modified (diff)

comment:3 Changed 22 months ago by Zach Bresser

Owner: changed from nobody to Zach Bresser
Status: newassigned

If my understanding is correct it should just be the following changes:

Changing JSON_CONTENT_TYPE_RE = re.compile(r'^application\/(vnd\..+\+)?json') to JSON_CONTENT_TYPE_RE = re.compile(r'^application\/(.+\+)?json' in django.test.client

As well as adding some tests. I can take this as my first PR.

comment:4 Changed 22 months ago by Simon Charette

Zach thanks for offer but it looks like there's already a PR that wasn't linked to this ticket

https://github.com/django/django/pull/10288

Last edited 22 months ago by Simon Charette (previous) (diff)

comment:5 Changed 22 months ago by Claude Paroz

Needs tests: unset

comment:6 Changed 22 months ago by Zach Bresser

Needs tests: set

comment:7 Changed 22 months ago by Zach Bresser

Needs tests: unset

I'm sorry Simon, I didn't realize. I have put in a PR, we make the same changes except I added a note in the Docs too. What is the next step? Close/Merge?

comment:8 Changed 22 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 7cc5225:

Fixed #29662 -- Allowed test client to accept structured suffix JSON content types.

comment:9 Changed 22 months ago by Tim Graham <timograham@…>

In ef30633:

[2.1.x] Fixed #29662 -- Allowed test client to accept structured suffix JSON content types.

Backport of 7cc52250f06c2a4769badbab1d7ee01f8e3cb46a from master

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