mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
REST API: Support a broader range of JSON media types.
Previously, we only supported `application/json` which prevented using subtypes like `application/activity+json`. This allows for the REST API to `json_decode` the body of requests using a JSON subtype `Content-Type`. Additionally, `wp_die()` now properly sends the error as JSON when a JSON subtype is specified in the `Accept` header. Props pfefferle. Fixes #49404. git-svn-id: https://develop.svn.wordpress.org/trunk@49329 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1728,4 +1728,27 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
array( '03:61:59', false ), // Out of bound.
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 49404
|
||||
* @dataProvider data_test_wp_is_json_media_type
|
||||
*/
|
||||
public function test_wp_is_json_media_type( $input, $expected ) {
|
||||
$this->assertEquals( $expected, wp_is_json_media_type( $input ) );
|
||||
}
|
||||
|
||||
|
||||
public function data_test_wp_is_json_media_type() {
|
||||
return array(
|
||||
array( 'application/ld+json', true ),
|
||||
array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', true ),
|
||||
array( 'application/activity+json', true ),
|
||||
array( 'application/json+oembed', true ),
|
||||
array( 'application/json', true ),
|
||||
array( 'application/nojson', false ),
|
||||
array( 'application/no.json', false ),
|
||||
array( 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8', false ),
|
||||
array( 'application/activity+json, application/nojson', true ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user