Don't double-unslash meta key when update_metadata()
falls back on add_metadata()
.
Props jdgrimes. Fixes #35795. git-svn-id: https://develop.svn.wordpress.org/trunk@36509 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d2cbbfe28b
commit
71060260a1
@ -161,6 +161,7 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v
|
||||
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
|
||||
|
||||
// expected_slashed ($meta_key)
|
||||
$raw_meta_key = $meta_key;
|
||||
$meta_key = wp_unslash($meta_key);
|
||||
$passed_value = $meta_value;
|
||||
$meta_value = wp_unslash($meta_value);
|
||||
@ -198,7 +199,7 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v
|
||||
|
||||
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) );
|
||||
if ( empty( $meta_ids ) ) {
|
||||
return add_metadata($meta_type, $object_id, $meta_key, $passed_value);
|
||||
return add_metadata( $meta_type, $object_id, $raw_meta_key, $passed_value );
|
||||
}
|
||||
|
||||
$_meta_value = $meta_value;
|
||||
|
30
tests/phpunit/tests/meta/updateMetadata.php
Normal file
30
tests/phpunit/tests/meta/updateMetadata.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group meta
|
||||
* @covers ::update_metadata
|
||||
*/
|
||||
class Tests_Meta_UpdateMetadata extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 35795
|
||||
*/
|
||||
public function test_slashed_key_for_new_metadata() {
|
||||
update_metadata( 'post', 123, wp_slash( 'foo\foo' ), 'bar' );
|
||||
|
||||
$found = get_metadata( 'post', 123, 'foo\foo', true );
|
||||
$this->assertSame( 'bar', $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35795
|
||||
*/
|
||||
public function test_slashed_key_for_existing_metadata() {
|
||||
global $wpdb;
|
||||
|
||||
add_metadata( 'post', 123, wp_slash( 'foo\foo' ), 'bar' );
|
||||
update_metadata( 'post', 123, wp_slash( 'foo\foo' ), 'baz' );
|
||||
|
||||
$found = get_metadata( 'post', 123, 'foo\foo', true );
|
||||
$this->assertSame( 'baz', $found );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user