From 3fc84c100c3e9cd0b3a829e2c599f277460cd657 Mon Sep 17 00:00:00 2001 From: ernilambar Date: Thu, 11 Aug 2016 11:44:13 +0545 Subject: [PATCH 1/2] Passed slashed data in meta --- php/WP_CLI/CommandWithMeta.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/php/WP_CLI/CommandWithMeta.php b/php/WP_CLI/CommandWithMeta.php index 0e8a07a39a..26c717c205 100644 --- a/php/WP_CLI/CommandWithMeta.php +++ b/php/WP_CLI/CommandWithMeta.php @@ -179,6 +179,7 @@ public function add( $args, $assoc_args ) { $object_id = $this->check_object_id( $object_id ); + $meta_value = wp_slash( $meta_value ); $success = add_metadata( $this->meta_type, $object_id, $meta_key, $meta_value ); if ( $success ) { @@ -221,6 +222,7 @@ public function update( $args, $assoc_args ) { if ( $meta_value === $old_value ) { WP_CLI::success( "Value passed for custom field '$meta_key' is unchanged." ); } else { + $meta_value = wp_slash( $meta_value ); $success = update_metadata( $this->meta_type, $object_id, $meta_key, $meta_value ); if ( $success ) { From 8281a5c44bdb856bb2a035fb7a79ac97c64a40eb Mon Sep 17 00:00:00 2001 From: ernilambar Date: Thu, 11 Aug 2016 11:49:09 +0545 Subject: [PATCH 2/2] Update test to reflect change in slashed data --- features/post-meta.feature | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/features/post-meta.feature b/features/post-meta.feature index a7eacd135f..e8dd92da3c 100644 --- a/features/post-meta.feature +++ b/features/post-meta.feature @@ -109,3 +109,33 @@ Feature: Manage post custom fields Then STDOUT should be a table containing rows: | post_id | meta_key | meta_value | | 1 | foo | | + + Scenario: Make sure WordPress receives the slashed data it expects in meta fields + Given a WP install + + When I run `wp post-meta add 1 foo 'My\Meta'` + Then STDOUT should not be empty + + When I run `wp post-meta get 1 foo` + Then STDOUT should be: + """ + My\Meta + """ + + When I run `wp post-meta update 1 foo 'My\New\Meta'` + Then STDOUT should be: + """ + Success: Updated custom field 'foo'. + """ + + When I run the previous command again + Then STDOUT should be: + """ + Success: Value passed for custom field 'foo' is unchanged. + """ + + When I run `wp post-meta get 1 foo` + Then STDOUT should be: + """ + My\New\Meta + """