Skip to content

Commit 7cc6bb5

Browse files
smithjw1claude
andauthored
Keep backslashes in ideation drafts and update-post-fields (#208)
* fix(ideation): keep backslashes in drafts created from a project wp_insert_post() unslashes its input, so the drafted title and block content lost every backslash: a code sample's C:\Users\tom was saved as C:Userstom. Slash the post array first, as StageAgent::write_content() does. Adds a success-path test for the create-draft route that configures a provider and cans its HTTP replies with pre_http_request, so the real route runs end to end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(abilities): keep backslashes in update-post-fields titles and excerpts wp_update_post() unslashes its input, so a backslash in a title or excerpt set through the ability was lost. Slash the update array before the call. The preview and the returned values stay unslashed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: cover backslashes through the REST routes, kses and other fields Run both #197 paths through rest_do_request(): the ideation create-draft route, and the update-post-fields ability's run route with REST visibility switched on for the test only. Decoded JSON input arrives unslashed, so the stored title, excerpt and block attributes keep single backslashes. Also cover an author without unfiltered_html, raw block attribute JSON, and author and date updates alongside a backslashed title. Give the preview fixture an empty excerpt, which the factory otherwise fills. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent abb9946 commit 7cc6bb5

4 files changed

Lines changed: 591 additions & 10 deletions

File tree

‎vip-workflows/includes/abilities/tools/update-post-fields.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ function execute_update_post_fields( ?array $input = null ) {
123123
$update_args[ $allowed_fields[ $field_name ] ] = $value;
124124
}
125125

126-
$result = wp_update_post( $update_args, true );
126+
// wp_update_post() unslashes what it's given, so slash it first.
127+
// Unslashed, every backslash in a title or excerpt is lost: `C:\temp`
128+
// is saved as `C:temp`. `$sanitized` stays unslashed for the response.
129+
$result = wp_update_post( wp_slash( $update_args ), true );
127130

128131
if ( is_wp_error( $result ) ) {
129132
return $result;

‎vip-workflows/includes/api/class-ideation-controller.php‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,18 @@ function ( $card ) use ( $pinned_ids ) {
895895

896896
$blocks = DraftBuilder::markdown_to_blocks( $body );
897897

898+
// wp_insert_post() unslashes what it's given, so slash it first.
899+
// Unslashed, every backslash in the drafted title and body is lost: a
900+
// code sample's `C:\Users\tom` is saved as `C:Userstom`.
898901
$post_id = wp_insert_post(
899-
array(
900-
'post_type' => 'post',
901-
'post_title' => $title,
902-
'post_content' => $blocks,
903-
'post_status' => 'draft',
904-
'post_author' => get_current_user_id(),
902+
wp_slash(
903+
array(
904+
'post_type' => 'post',
905+
'post_title' => $title,
906+
'post_content' => $blocks,
907+
'post_status' => 'draft',
908+
'post_author' => get_current_user_id(),
909+
)
905910
),
906911
true
907912
);

0 commit comments

Comments
 (0)