Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#27550 closed defect (bug) (fixed)

Incorrect slashing in `wp_trash_post()` and `wp_untrash_post()`

Reported by: denis-de-bernardy's profile Denis-de-Bernardy Owned by: johnbillion's profile johnbillion
Milestone: 4.4 Priority: normal
Severity: major Version: 2.9
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:


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)

27550.diff (619 bytes) - added by Denis-de-Bernardy 10 years ago.
27550-phpunit-test.diff (1.0 KB) - added by dmenard 9 years ago.
PhpUnit test showing the bug
27550-patch-refreshed.diff (645 bytes) - added by dmenard 9 years ago.
Denis patch refreshed against current trunk

Download all attachments as: .zip

Change History (11)

#1 @Denis-de-Bernardy
10 years ago

  • Severity changed from normal to major

#2 @dd32
10 years ago

  • Version changed from trunk to 2.9

#3 @Denis-de-Bernardy
10 years ago

Patch attached.

#4 @nacin
10 years ago

  • Keywords has-patch needs-unit-tests added

9 years ago

PhpUnit test showing the bug

9 years ago

Denis patch refreshed against current trunk

#5 @dmenard
9 years ago


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 '                                            
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!


#6 @johnbillion
9 years ago

  • Keywords needs-unit-tests removed
  • Milestone changed from Awaiting Review to 4.4
  • Owner set to johnbillion
  • Status changed from new to reviewing

#7 @johnbillion
9 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 34668:

Correctly slash post fields when trashing and untrashing posts.

Fixes #27550
Props dmenard, Denis-de-Bernardy

#8 @dmenard
9 years ago

Great, thank you @johnbillion!

Note: See TracTickets for help on using tickets.