[wp-trac] [WordPress Trac] #48363: Empty string in database for boolean meta not cast to false
WordPress Trac
noreply at wordpress.org
Fri Oct 18 00:18:22 UTC 2019
#48363: Empty string in database for boolean meta not cast to false
-------------------------------------------------+-------------------------
Reporter: chrisvanpatten | Owner:
| TimothyBlynJacobs
Type: defect (bug) | Status: accepted
Priority: normal | Milestone: 5.3
Component: REST API | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests dev- | Focuses: rest-api
feedback 2nd-opinion |
-------------------------------------------------+-------------------------
Changes (by TimothyBlynJacobs):
* keywords: => has-patch has-unit-tests dev-feedback 2nd-opinion
* owner: (none) => TimothyBlynJacobs
* status: new => accepted
* milestone: Awaiting Review => 5.3
Comment:
The specific regression here is that we are instead validating and
sanitizing the output of `get_metadata` instead of simply casting it to
its primitive type. Discussing with @kadamwhite, I think the fix here is
to check if `get_metadata` returns an empty string, and if so, return the
default value instead.
This effects the settings controller in a similar way, but I think it'd be
best to address that in a separate ticket for 5.4.
{{{#!php
<?php
function test_get_item_with_false_stored_for_integer_value() {
wp_set_current_user( self::$administrator );
register_setting(
'somegroup',
'mycustomsetting',
array(
'type' => 'integer',
'show_in_rest' => true,
)
);
$request = new WP_REST_Request( 'GET', '/wp/v2/settings' );
$response = rest_get_server()->dispatch( $request );
$this->assertSame( 0, $response->get_data()['mycustomsetting'] );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48363#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list