REST API: Do not error on empty JSON body

It's fairly common for clients to send `Content-Type: application/json` with an
empty body.  While technically not valid JSON, we've historically supported
this behaviour, so it shouldn't cause an error.

Props JPry, jnylen0.
Merges [39594] to the 4.7 branch.
Fixes #39150.

Built from https://develop.svn.wordpress.org/branches/4.7@39609


git-svn-id: http://core.svn.wordpress.org/branches/4.7@39549 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2016-12-16 05:43:33 +00:00
parent 72d9177fc0
commit 0b813f2544
2 changed files with 7 additions and 2 deletions

View File

@ -669,7 +669,12 @@ class WP_REST_Request implements ArrayAccess {
return true;
}
$params = json_decode( $this->get_body(), true );
$body = $this->get_body();
if ( empty( $body ) ) {
return true;
}
$params = json_decode( $body, true );
/*
* Check for a parsing error.

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7.1-alpha-39608';
$wp_version = '4.7.1-alpha-39609';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.