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 |
| 161 | 161 | $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
| 162 | 162 | |
| 163 | 163 | // expected_slashed ($meta_key) |
| | 164 | $raw_meta_key = $meta_key; |
| 164 | 165 | $meta_key = wp_unslash($meta_key); |
| 165 | 166 | $passed_value = $meta_value; |
| 166 | 167 | $meta_value = wp_unslash($meta_value); |
| … |
… |
function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v |
| 198 | 199 | |
| 199 | 200 | $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ); |
| 200 | 201 | 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); |
| 202 | 203 | } |
| 203 | 204 | |
| 204 | 205 | $_meta_value = $meta_value; |
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 | */ |
| | 7 | class 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, '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, 'foo\\\\foo', 'bar' ); |
| | 25 | update_metadata( 'post', 123, 'foo\\\\foo', 'baz' ); |
| | 26 | |
| | 27 | $found = get_metadata( 'post', 123, 'foo\foo', true ); |
| | 28 | $this->assertSame( 'baz', $found ); |
| | 29 | } |
| | 30 | } |