Make WordPress Core

Ticket #37746: 37746.2.diff

File 37746.2.diff, 3.1 KB (added by peterwilsoncc, 8 years ago)
  • src/wp-includes/meta.php

    diff --git src/wp-includes/meta.php src/wp-includes/meta.php
    index 8833d3e..b7ea2af 100644
    function metadata_exists( $meta_type, $object_id, $meta_key ) { 
    567567function get_metadata_by_mid( $meta_type, $meta_id ) {
    568568        global $wpdb;
    569569
    570         if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
     570        if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
    571571                return false;
    572572        }
    573573
    574         $meta_id = absint( $meta_id );
    575         if ( ! $meta_id ) {
     574        $meta_id = intval( $meta_id );
     575        if ( $meta_id <= 0 ) {
    576576                return false;
    577577        }
    578578
    function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = 
    611611        global $wpdb;
    612612
    613613        // Make sure everything is valid.
    614         if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
     614        if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
    615615                return false;
    616616        }
    617617
    618         $meta_id = absint( $meta_id );
    619         if ( ! $meta_id ) {
     618        $meta_id = intval( $meta_id );
     619        if ( $meta_id <= 0 ) {
    620620                return false;
    621621        }
    622622
    function delete_metadata_by_mid( $meta_type, $meta_id ) { 
    702702        global $wpdb;
    703703
    704704        // Make sure everything is valid.
    705         if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
     705        if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
    706706                return false;
    707707        }
    708708
    709         $meta_id = absint( $meta_id );
    710         if ( ! $meta_id ) {
     709        $meta_id = intval( $meta_id );
     710        if ( $meta_id <= 0 ) {
    711711                return false;
    712712        }
    713713
  • tests/phpunit/tests/meta.php

    diff --git tests/phpunit/tests/meta.php tests/phpunit/tests/meta.php
    index 0676c7e..eb6f2c5 100644
    class Tests_Meta extends WP_UnitTestCase { 
    293293        }
    294294
    295295        /**
     296         * @ticket 37746
     297         */
     298        function test_negative_meta_id() {
     299                $negative_mid = $this->meta_id * -1;
     300
     301                $this->assertTrue( $negative_mid < 0 );
     302                $this->assertFalse( get_metadata_by_mid( 'user', $negative_mid ) );
     303                $this->assertFalse( update_metadata_by_mid( 'user', $negative_mid, 'meta_new_value' ) );
     304                $this->assertFalse( delete_metadata_by_mid( 'user', $negative_mid ) );
     305        }
     306
     307        /**
     308         * @ticket 37746
     309         */
     310        function test_floating_meta_id() {
     311                $floating_mid = $this->meta_id + 0.1337;
     312
     313                $this->assertTrue( floor( $floating_mid ) !== $floating_mid );
     314                $this->assertFalse( get_metadata_by_mid( 'user', $floating_mid ) );
     315                $this->assertFalse( update_metadata_by_mid( 'user', $floating_mid, 'meta_new_value' ) );
     316                $this->assertFalse( delete_metadata_by_mid( 'user', $floating_mid ) );
     317        }
     318
     319        /**
     320         * @ticket 37746
     321         */
     322        function test_string_point_zero_meta_id() {
     323                $meta_id = add_metadata( 'user', $this->author->ID, 'meta_key', 'meta_value_2' );
     324
     325                $string_mid = "{$meta_id}.0";
     326
     327                $this->assertTrue( floor( $string_mid ) == $string_mid );
     328                $this->assertNotEquals( false, get_metadata_by_mid( 'user', $string_mid ) );
     329                $this->assertNotEquals( false, update_metadata_by_mid( 'user', $string_mid, 'meta_new_value_2' ) );
     330                $this->assertNotEquals( false, delete_metadata_by_mid( 'user', $string_mid ) );
     331        }
     332
     333        /**
    296334         * @ticket 15030
    297335         */
    298336        public function test_get_metadata_with_empty_key_array_value() {