Make WordPress Core


Ignore:
Timestamp:
12/13/2016 03:33:14 AM (10 years ago)
Author:
jnylen0
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-request.php

    r39563 r39594  
    670670                }
    671671
    672                 $params = json_decode( $this->get_body(), true );
     672                $body = $this->get_body();
     673                if ( empty( $body ) ) {
     674                        return true;
     675                }
     676
     677                $params = json_decode( $body, true );
    673678
    674679                /*
Note: See TracChangeset for help on using the changeset viewer.