[wp-trac] [WordPress Trac] #30471: json_encode() fails on non-utf8 strings

WordPress Trac noreply at wordpress.org
Mon Nov 24 02:03:18 UTC 2014


#30471: json_encode() fails on non-utf8 strings
--------------------------+------------------------------
 Reporter:  pento         |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+------------------------------
Changes (by pento):

 * keywords:   => has-patch


Comment:

 [attachment:30471.diff] fixes this for plain strings.

 Walking through arbitrary arrays/objects to check for non UTF-8 characters
 isn't a good option.

 Maybe we could do a lazy check for `$json` containing the string `null`,
 and `version_compare( PHP_VERSION, '5.4', '<=' )`? This will give false
 positives when `$data` contains an array or object with a `null` value,
 but it's a lot faster than an element-by-element check.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30471#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list