[wp-trac] [WordPress Trac] #56119: `wp_unslash()` and `wp_slash()` do not (un)slash the same data.

WordPress Trac noreply at wordpress.org
Tue Jul 5 04:08:41 UTC 2022


#56119: `wp_unslash()` and `wp_slash()` do not (un)slash the same data.
-------------------------------------------+------------------------------
 Reporter:  peterwilsoncc                  |       Owner:  (none)
     Type:  defect (bug)                   |      Status:  new
 Priority:  normal                         |   Milestone:  Awaiting Review
Component:  Formatting                     |     Version:
 Severity:  normal                         |  Resolution:
 Keywords:  reporter-feedback 2nd-opinion  |     Focuses:
-------------------------------------------+------------------------------
Changes (by costdev):

 * keywords:   => reporter-feedback 2nd-opinion


Comment:

 It seems that using the following from the deprecated
 `wp_slash_strings_only`
 [https://developer.wordpress.org/reference/functions/wp_slash_strings_only/
 Ref] does the trick here:

 {{{#!php
 <?php
 function wp_slash( $value ) {
         return map_deep( $value, 'addslashes_strings_only' );
 }
 }}}

 `addslashes_strings_only()`
 [https://developer.wordpress.org/reference/functions/addslashes_strings_only/
 Ref] is also deprecated, but this might mean it's a candidate for
 undeprecating?


 I modified the tests to use slashable characters, as `wp_slash()` has no
 way to know that the second "s" should be slashed in `slsh`:

 {{{#!php
 <?php
 /**
  * @ticket 56119
  */
 public function test_slash_unslash_reversable() {
         $expected = (object) array( 'data' => 'sl"sh' );
         $actual   = wp_unslash( wp_slash( clone( $expected ) ) );

         $this->assertSame( $expected->data, $actual->data );
 }

 /**
  * @ticket 56119
  */
 public function test_unslash_slash_reversable() {
         $expected = (object) array( 'data' => 'sl\"sh' );
         $actual   = wp_slash( wp_unslash( clone( $expected ) ) );

         $this->assertSame( $expected->data, $actual->data );
 }
 }}}

 What do you think @peterwilsoncc?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56119#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list