Make WordPress Core

Ticket #35795: 35795.2.diff

File 35795.2.diff, 1.9 KB (added by jdgrimes, 9 years ago)

Same as previous, but using wp_slash()

  • src/wp-includes/meta.php

    diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php
    index 19ce664..893cfc5 100644
    a b function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v 
    161161        $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
    162162
    163163        // expected_slashed ($meta_key)
     164        $raw_meta_key = $meta_key;
    164165        $meta_key = wp_unslash($meta_key);
    165166        $passed_value = $meta_value;
    166167        $meta_value = wp_unslash($meta_value);
    function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v 
    198199
    199200        $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) );
    200201        if ( empty( $meta_ids ) ) {
    201                 return add_metadata($meta_type, $object_id, $meta_key, $passed_value);
     202                return add_metadata($meta_type, $object_id, $raw_meta_key, $passed_value);
    202203        }
    203204
    204205        $_meta_value = $meta_value;
  • new file tests/phpunit/tests/meta/updateMetadata.php

    diff --git a/tests/phpunit/tests/meta/updateMetadata.php b/tests/phpunit/tests/meta/updateMetadata.php
    new file mode 100644
    index 0000000..e78d9e1
    - +  
     1<?php
     2
     3/**
     4 * @group meta
     5 * @covers ::update_metadata
     6 */
     7class Tests_Meta_UpdateMetadata extends WP_UnitTestCase {
     8        /**
     9         * @ticket 35795
     10         */
     11        public function test_slashed_key_for_new_metadata() {
     12                update_metadata( 'post', 123, wp_slash( 'foo\foo' ), 'bar' );
     13
     14                $found = get_metadata( 'post', 123, 'foo\foo', true );
     15                $this->assertSame( 'bar', $found );
     16        }
     17
     18        /**
     19         * @ticket 35795
     20         */
     21        public function test_slashed_key_for_existing_metadata() {
     22                global $wpdb;
     23
     24                add_metadata( 'post', 123, wp_slash( 'foo\foo' ), 'bar' );
     25                update_metadata( 'post', 123, wp_slash( 'foo\foo' ), 'baz' );
     26
     27                $found = get_metadata( 'post', 123, 'foo\foo', true );
     28                $this->assertSame( 'baz', $found );
     29        }
     30}