Opened 4 years ago
Last modified 4 days ago
#53023 new defect (bug)
_wp_json_convert_string type mismatch: returns string on success; false on failure
Reported by: | hellofromTonya | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.1.4 |
Component: | Formatting | Keywords: | |
Focuses: | docs | Cc: |
Description
The private function _wp_json_convert_string
(which converts a string to UTF-8) also returns false
, though its @return
specifies only string
.
How? `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 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.)
#57172 was marked as a duplicate.