[wp-trac] [WordPress Trac] #39755: Rest API json string corruption?
WordPress Trac
noreply at wordpress.org
Wed Feb 1 05:35:49 UTC 2017
#39755: Rest API json string corruption?
--------------------------+-----------------------------
Reporter: sgehrman | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 4.7.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
I set up a new install of WP. Register a rest route. It returns json
with string with spaces in it.
I expect to get back: {"wtf": 'w t
f'}
But I get {"wtf" => 'w t f'}
I call $.post() from my client.
Why are the multiple spaces in my string converted to one space? Data
corruption!
I spent the day googling this, and didn't find anyone who could explain
why this is happening. Is there some config I don't know about that needs
to be setup to not corrupt the data?
{{{#!php
<?php
add_action( 'rest_api_init', 'setupRESTApi' );
function setupRESTApi() {
register_rest_route( 'api', '/rest', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'endpoint_rest'
) );
}
// WP_REST_Request
function endpoint_rest( $request ) {
$result = ["wtf" => 'w t
f'];
return rest_ensure_response( $result );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39755>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list