#27550 closed defect (bug) (fixed)
Incorrect slashing in `wp_trash_post()` and `wp_untrash_post()`
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.4 | Priority: | normal |
| Severity: | major | Version: | 2.9 |
| Component: | Posts, Post Types | Keywords: | has-patch |
| Focuses: | Cc: |
Description
wp_trash_post() uses get_post($post_id, ARRAY_A), but then fails to slash the data prior to calling wp_insert_post(). The same for wp_untrash_post().
I'm pretty certain wp_insert_post() expects slashed data when receiving an array of data.
Attachments (3)
Change History (11)
#5
@
10 years ago
Hi!
We're experiencing this bug too.
In our case, we're storing JSON snippets in post_excerpt/post_content and when a post is trashed (and then untrashed), the json becomes invalid because the backslashes are removed by wp_trash_post().
The patch by Denis (just two lines) solves the problem, so I have uploaded a phpunit test which shows the problem and fails with current code:
$ phpunit tests/phpunit/tests/post/slashes.php
1) Tests_Post_Slashes::test_wp_trash_untrash
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'String with 1 slash \'
+'String with 1 slash '
\wordpress-develop\tests\phpunit\tests\post\slashes.php:145
FAILURES!
Tests: 4, Assertions: 19, Failures: 1.
And I have refreshed Denis patch against current trunk:
$ phpunit tests/phpunit/tests/post/slashes.php OK (4 tests, 24 assertions)
This is my first try at contributing to WordPress, hope I did it right...
It would be great to get this bug fixed!
Cheers
Patch attached.