From 0b599cce41077ce20b3ea3027bf596cc0a2c9a3b Mon Sep 17 00:00:00 2001 From: James Nylen Date: Tue, 13 Dec 2016 03:34:41 +0000 Subject: [PATCH] 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. Fixes #39150. Built from https://develop.svn.wordpress.org/trunk@39594 git-svn-id: http://core.svn.wordpress.org/trunk@39534 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/rest-api/class-wp-rest-request.php | 7 ++++++- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/wp-includes/rest-api/class-wp-rest-request.php b/wp-includes/rest-api/class-wp-rest-request.php index d37ab6175d..4dd0dc2090 100644 --- a/wp-includes/rest-api/class-wp-rest-request.php +++ b/wp-includes/rest-api/class-wp-rest-request.php @@ -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. diff --git a/wp-includes/version.php b/wp-includes/version.php index 79aa664a04..c6a5eb4c7c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-alpha-39593'; +$wp_version = '4.8-alpha-39594'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.