Make WordPress Core


Ignore:
Timestamp:
02/04/2026 06:51:51 PM (10 months ago)
Author:
westonruter
Message:

Formatting: Deprecate the addslashes_gpc() function.

This deprecates addslashes_gpc() in favor of wp_slash(), as the former is just a wrapper for the latter. The three remaining uses of addslashes_gpc() (in WP_Query) have been replaced with wp_slash(). Unit tests are added to verify that they have the same behavior.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/10771

Follow-up to [23591], [23555].

Props rutviksavsani, audrasjb, westonruter, mindctrl, johnbillion.
See #21767.
Fixes #64539.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/wpSlash.php

    r56547 r61590  
    102102                $this->assertSame( array( $new ), wp_slash( array( $old ) ) ); // Non-keyed.
    103103        }
     104
     105        /**
     106         * Tests that addslashes_gpc() returns the same result as wp_slash() for strings.
     107         *
     108         * @ticket 64539
     109         * @covers ::addslashes_gpc
     110         * @expectedDeprecated addslashes_gpc
     111         */
     112        public function test_addslashes_gpc_matches_wp_slash_for_strings() {
     113                $input = "String with 'quotes' and \"double quotes\"";
     114                $this->assertSame( wp_slash( $input ), addslashes_gpc( $input ) );
     115        }
     116
     117        /**
     118         * Tests that addslashes_gpc() returns the same result as wp_slash() for arrays.
     119         *
     120         * @ticket 64539
     121         * @covers ::addslashes_gpc
     122         * @expectedDeprecated addslashes_gpc
     123         */
     124        public function test_addslashes_gpc_matches_wp_slash_for_arrays() {
     125                $input = array(
     126                        'field1' => "Value with 'apostrophe'",
     127                        'field2' => 'Value with "quotes"',
     128                        'field3' => 'user@example.com',
     129                        'nested' => array(
     130                                'key1' => 'Nested value with \\ backslash',
     131                                'key2' => array( 'deeply', 'nested', 'array' ),
     132                        ),
     133                );
     134
     135                $this->assertSame( wp_slash( $input ), addslashes_gpc( $input ) );
     136        }
    104137}
Note: See TracChangeset for help on using the changeset viewer.