From 8dcc10693f45de8e75916f9056a6a32e85a064b9 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Thu, 15 Aug 2019 19:56:55 +0000 Subject: [PATCH] REST API: Do not send response body if status is 204 or body is null. Status code 204 should indicate no response body is sent. Previously, a "null" string was sent, which MacOS Safari would try to parse as JSON and thereby fail to complete the request. Props TimothyBlynJacobs, andizer, matthias.thiel. Fixes #43691. Built from https://develop.svn.wordpress.org/trunk@45809 git-svn-id: http://core.svn.wordpress.org/trunk@45620 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/rest-api/class-wp-rest-server.php | 5 +++++ wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/class-wp-rest-server.php b/wp-includes/rest-api/class-wp-rest-server.php index 68be073eef..7f158959e9 100644 --- a/wp-includes/rest-api/class-wp-rest-server.php +++ b/wp-includes/rest-api/class-wp-rest-server.php @@ -405,6 +405,11 @@ class WP_REST_Server { */ $result = apply_filters( 'rest_pre_echo_response', $result, $this, $request ); + // The 204 response shouldn't have a body. + if ( 204 === $code || null === $result ) { + return null; + } + $result = wp_json_encode( $result ); $json_error_message = $this->get_json_last_error(); diff --git a/wp-includes/version.php b/wp-includes/version.php index 3d4fc6d0fe..89c22e19d5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45808'; +$wp_version = '5.3-alpha-45809'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.