[wp-trac] [WordPress Trac] #42069: Saving metadata fails (randomly) if equal value already exists
WordPress Trac
noreply at wordpress.org
Thu Feb 15 22:09:43 UTC 2018
#42069: Saving metadata fails (randomly) if equal value already exists
--------------------------+------------------------------
Reporter: JVel | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 4.8.2
Severity: normal | Resolution:
Keywords: has-patch | Focuses: rest-api
--------------------------+------------------------------
Changes (by dcavins):
* keywords: => has-patch
Comment:
I too ran into this problem today and was able to identify two cases where
`WP_REST_Meta_Fields::update_meta_value()` was failing to interpret the
values as identical, but `update_metadata()` was returning false (because
the values were considered equal by that function), so the REST request
was getting a 500 error back. These two cases are problematic:
• Text containing characters that are slashed or converted to entities,
like `"` or `<`.
• Booleans, like a checkbox, that, when unchecked, pass the integer `0`.
In the first case, the comparison in
`WP_REST_Meta_Fields::update_meta_value()` tries to strict compare `<`
to `<`, and, in the second case, the string `'0'` (all saved meta is
strings) is compared to the incoming sanitized value of `(int) 0`.
I've created a diff with tests showing these failures and a proposed patch
to improve the comparison in `WP_REST_Meta_Fields::update_meta_value()` so
that it catches more cases that `update_metadata()` or `$wpdb->query()`
will consider equal.
If there are other cases that I can write tests for, please describe the
situation in detail in your comments. I'd like to find all failures and
make sure that the fix works for all of them.
Thanks for your comments!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42069#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list