Make WordPress Core

Opened 13 years ago

Closed 11 years ago

Last modified 11 years ago

#27550 closed defect (bug) (fixed)

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

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

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)

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

Download all attachments as: .zip

Change History (11)

#1 @Denis-de-Bernardy
13 years ago

  • Severity normal → major

#2 @dd32
13 years ago

  • Version trunk → 2.9

#3 @Denis-de-Bernardy
13 years ago

Patch attached.

#4 @nacin
13 years ago

  • Keywords has-patch needs-unit-tests added

@dmenard
11 years ago

PhpUnit test showing the bug

@dmenard
11 years ago

Denis patch refreshed against current trunk

#5 @dmenard
11 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

#6 @johnbillion
11 years ago

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

#7 @johnbillion
11 years ago

  • Resolution → fixed
  • Status reviewing → closed

In 34668:

Correctly slash post fields when trashing and untrashing posts.

Fixes #27550
Props dmenard, Denis-de-Bernardy

#8 @dmenard
11 years ago

Great, thank you @johnbillion!

Note: See TracTickets for help on using tickets.