General: Ensure consistent type for integer properties of a bookmark object.

Previously, these properties could be unexpectedly converted to strings in some contexts.

This applies to the following function:

* `sanitize_bookmark_field()`

and the following properties:

* `$bookmark::link_id`
* `$bookmark::link_rating`

Follow-up to [50935].

See #53235.
Built from https://develop.svn.wordpress.org/trunk@50936


git-svn-id: http://core.svn.wordpress.org/trunk@50545 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-05-20 00:04:56 +00:00
parent 893beee31e
commit cf90ff2427
2 changed files with 13 additions and 7 deletions

View File

@ -391,16 +391,17 @@ function sanitize_bookmark( $bookmark, $context = 'display' ) {
* @param string $field The bookmark field.
* @param mixed $value The bookmark field value.
* @param int $bookmark_id Bookmark ID.
* @param string $context How to filter the field value. Accepts 'raw', 'edit', 'attribute',
* 'js', 'db', or 'display'
* @param string $context How to filter the field value. Accepts 'raw', 'edit', 'db',
* 'display', 'attribute', or 'js'. Default 'display'.
* @return mixed The filtered value.
*/
function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) {
$int_fields = array( 'link_id', 'link_rating' );
if ( in_array( $field, $int_fields, true ) ) {
$value = (int) $value;
}
switch ( $field ) {
case 'link_id': // ints
case 'link_rating':
$value = (int) $value;
break;
case 'link_category': // array( ints )
$value = array_map( 'absint', (array) $value );
// We return here so that the categories aren't filtered.
@ -445,6 +446,11 @@ function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) {
}
}
// Restore the type for integer fields after esc_attr().
if ( in_array( $field, $int_fields, true ) ) {
$value = (int) $value;
}
return $value;
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.8-alpha-50935';
$wp_version = '5.8-alpha-50936';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.