[wp-trac] [WordPress Trac] #40560: REST API: Unicode characters are escaped in the response
WordPress Trac
noreply at wordpress.org
Tue Apr 25 05:02:28 UTC 2017
#40560: REST API: Unicode characters are escaped in the response
--------------------------+-----------------------------
Reporter: rilwis | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
When working with languages with unicode characters (Vietnamese, to be
precisely), the returned result of REST API requests contains escaped
characters.
This is an example:
{{{
{"hoten":"Test ko dien thong tin thi
sinh","email":"","sodienthoai":"123123","nganhhoc":"CNTT - \u1ee8ng
d\u1ee5ng ph\u1ea7n m\u1ec1m","ma_nganhhoc":"CNTT","diadiemhoc":"H\u00e0
N\u1ed9i","ma_diadiemhoc":"HN","tongtien":8925000}
}}}
The expected result is:
{{{
{"hoten":"Test ko dien thong tin thi
sinh","email":"","sodienthoai":"123123","nganhhoc":"CNTT - Ứng dụng phần
mềm","ma_nganhhoc":"CNTT","diadiemhoc":"Hà
Nội","ma_diadiemhoc":"HN","tongtien":8925000}
}}}
When looking at the `WP_REST_Server::serve_request` function, I see that
it uses `wp_json_encode` function. While this function
[https://secure.php.net/json_encode accepts options], they're never been
used. In this case, the option `JSON_UNESCAPED_UNICODE` is all we need.
Although the option is added in PHP 5.3 and we can't guarantee it work in
all situation. But we should make an option in the REST API so developers
can have a way to accomplish the job.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40560>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list