From f196c38ab41c5851a6625e82259c6f6128e75cf9 Mon Sep 17 00:00:00 2001 From: Muhibul Haque Date: Sun, 1 Nov 2026 16:48:50 +0600 Subject: [PATCH 1/2] Tests: Cover stripslashes_from_strings_only(). See #65819. Props devmuhib009. --- .../tests/formatting/stripslashesDeep.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/phpunit/tests/formatting/stripslashesDeep.php b/tests/phpunit/tests/formatting/stripslashesDeep.php index b88966cc3427f..ca78d5b43284f 100644 --- a/tests/phpunit/tests/formatting/stripslashesDeep.php +++ b/tests/phpunit/tests/formatting/stripslashesDeep.php @@ -5,6 +5,7 @@ * @group slashes * * @covers ::stripslashes_deep + * @covers ::stripslashes_from_strings_only */ class Tests_Formatting_StripslashesDeep extends WP_UnitTestCase { /** @@ -55,4 +56,45 @@ public function test_permits_escaped_slash() { $this->assertSame( $txt, stripslashes_deep( "I can\'t see, isn\\\'t that it?" ) ); $this->assertSame( $txt, stripslashes_deep( "I can\'t see, isn\\\\\'t that it?" ) ); } + + /** + * Tests that stripslashes_from_strings_only() strips slashes from strings. + * + * @ticket 65819 + * + * @covers ::stripslashes_from_strings_only + */ + public function test_stripslashes_from_strings_only_with_string() { + $this->assertSame( "I can't see, isn't that it?", stripslashes_from_strings_only( "I can\'t see, isn\'t that it?" ) ); + } + + /** + * Tests that stripslashes_from_strings_only() preserves non-string values. + * + * @ticket 65819 + * + * @covers ::stripslashes_from_strings_only + * + * @dataProvider data_non_string_values + * + * @param mixed $value Non-string value. + */ + public function test_stripslashes_from_strings_only_with_non_string( $value ) { + $this->assertSame( $value, stripslashes_from_strings_only( $value ) ); + } + + /** + * Data provider for test_stripslashes_from_strings_only_with_non_string(). + * + * @return array[] + */ + public static function data_non_string_values() { + return array( + 'integer' => array( 42 ), + 'float' => array( 3.14 ), + 'boolean true' => array( true ), + 'null' => array( null ), + 'array' => array( array( 'a', 'b' ) ), + ); + } } From 728bb7b06f17ce5ed64ac01aa8c717d000b0c51f Mon Sep 17 00:00:00 2001 From: Muhibul Haque Date: Mon, 2 Nov 2026 15:23:03 +0600 Subject: [PATCH 2/2] Tests: Focus stripslashes_from_strings_only() coverage on non-recursive array contract. --- .../tests/formatting/stripslashesDeep.php | 38 +++---------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/tests/phpunit/tests/formatting/stripslashesDeep.php b/tests/phpunit/tests/formatting/stripslashesDeep.php index ca78d5b43284f..e090b41a3dc98 100644 --- a/tests/phpunit/tests/formatting/stripslashesDeep.php +++ b/tests/phpunit/tests/formatting/stripslashesDeep.php @@ -58,43 +58,15 @@ public function test_permits_escaped_slash() { } /** - * Tests that stripslashes_from_strings_only() strips slashes from strings. + * Tests that stripslashes_from_strings_only() does not strip slashes from array elements. * - * @ticket 65819 - * - * @covers ::stripslashes_from_strings_only - */ - public function test_stripslashes_from_strings_only_with_string() { - $this->assertSame( "I can't see, isn't that it?", stripslashes_from_strings_only( "I can\'t see, isn\'t that it?" ) ); - } - - /** - * Tests that stripslashes_from_strings_only() preserves non-string values. + * Unlike stripslashes_deep(), stripslashes_from_strings_only() does not recurse into arrays. * * @ticket 65819 - * - * @covers ::stripslashes_from_strings_only - * - * @dataProvider data_non_string_values - * - * @param mixed $value Non-string value. */ - public function test_stripslashes_from_strings_only_with_non_string( $value ) { - $this->assertSame( $value, stripslashes_from_strings_only( $value ) ); - } + public function test_stripslashes_from_strings_only_does_not_strip_array() { + $slashed_array = array( "I can\'t see", 'b' ); - /** - * Data provider for test_stripslashes_from_strings_only_with_non_string(). - * - * @return array[] - */ - public static function data_non_string_values() { - return array( - 'integer' => array( 42 ), - 'float' => array( 3.14 ), - 'boolean true' => array( true ), - 'null' => array( null ), - 'array' => array( array( 'a', 'b' ) ), - ); + $this->assertSame( $slashed_array, stripslashes_from_strings_only( $slashed_array ) ); } }