Copy Post: fix backslash characters being stripped when duplicating a post#48870
Merged
Gilmoursa merged 3 commits intoMay 15, 2026
Merged
Conversation
wp_update_post() / wp_insert_post() calls wp_unslash() internally because it expects slashed $_POST-style data. Passing raw DB content (e.g. from get_post()) directly caused backslash sequences like \t, \n, and \\ to be stripped from post_content, post_title, and post_excerpt. Wrap the data array with wp_slash() before calling wp_update_post() so the backslashes survive the internal wp_unslash() call. Adds a regression test using ReflectionMethod to invoke the protected update_content() method and assert all three fields are preserved. Fixes Automattic#46020 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
factory()->post->create() calls wp_insert_post() directly, which calls wp_unslash() internally (as it expects slashed $_POST-style input). Without wp_slash() on the test data, PHP's stripslashes() strips backslashes from the source post before it's even read, causing the assertion to compare against a string with backslashes that was never stored. Wrap the factory args with wp_slash() to match how WordPress normally receives post data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove multi-line description from docblock (PHPCS requires long descriptions to start with a capital letter) - Guard setAccessible(true) behind PHP_VERSION_ID < 80100 since ReflectionMethod::setAccessible() is deprecated in PHP 8.5 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #46020
Proposed changes
wp_update_post()callswp_unslash()internally because it expects WordPress-style slashed data (as received from$_POST). The Copy Post module passed raw database content fromget_post()directly — content that is already unslashed — so backslash sequences like\t,\n,\\, and\fwere silently stripped frompost_content,post_title, andpost_excerptwhen duplicating a post.Fix: wrap the data array with
wp_slash()before callingwp_update_post()inupdate_content(), which is the standard WordPress pattern for passing programmatically-constructed post data.One-line change:
Also adds a regression test using
ReflectionMethodto invoke the protectedupdate_content()method and assert that backslashes in all three fields are preserved after the copy.Does this pull request change what data or activity we track or use?
No. This is a bug fix for data fidelity during post duplication. No tracking or privacy-relevant behaviour is changed.
Testing instructions
\t is a taband a paragraph with\\escaped\\.\t is a tabbecomest is a tab;\\escaped\\becomes\escaped\🤖 Generated with Claude Code