[wp-trac] [WordPress Trac] #53023: _wp_json_convert_string type mismatch: returns string on success; false on failure

WordPress Trac noreply at wordpress.org
Mon Apr 12 21:07:07 UTC 2021


#53023: _wp_json_convert_string type mismatch: returns string on success; false on
failure
----------------------------+-----------------------------
 Reporter:  hellofromTonya  |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Formatting      |    Version:  4.1.4
 Severity:  normal          |   Keywords:
  Focuses:  docs            |
----------------------------+-----------------------------
 The private function `_wp_json_convert_string` (which converts a string to
 UTF-8) also returns `false`, though its `@return` specifies only `string`.

 How? [https://www.php.net/manual/en/function.mb-convert-encoding.php
 `mb_convert_encoding`] returns a `string` on success and a `false` on
 failure.

 Is this a bug or docs fix? It's both.

 Reviewing its context, it's used by `_wp_json_sanity_check` to convert IDs
 and data value. The IDs are the problem. How so? Each ID is used as either
 a key or project for referencing the data value.

 What happens if the conversion to UTF-8 fails? The key or property would
 either be an empty string or `false`. That's problematic as it can cause
 unexpected JSON encoding results.

 For example, this [https://3v4l.org/n4qT6 3v4l snippet] simulates the
 convert encoding failure to view the results through the JSON encoding
 process. Notice how the returned JSON is invalid when it fails. (Note:
 This snippet is forcing a failure.)

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53023>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list